@atlaskit/eslint-plugin-ui-styling-standard 0.6.0 → 0.6.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.
- package/CHANGELOG.md +7 -0
- package/README.md +16 -15
- package/constellation/convert-props-syntax/usage.mdx +115 -0
- package/constellation/index/overview.mdx +16 -15
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/convert-props-syntax/index.js +396 -0
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/utils/is-supported-import.js +7 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/convert-props-syntax/index.js +291 -0
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/utils/is-supported-import.js +7 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/convert-props-syntax/index.js +389 -0
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/utils/is-supported-import.js +7 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/convert-props-syntax/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/convert-props-syntax/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/package.json +5 -3
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/convert-props-syntax/README.md +113 -0
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +76 -0
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +422 -0
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +140 -0
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +69 -0
- package/src/rules/convert-props-syntax/index.tsx +414 -0
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/utils/README.md +1 -0
- package/src/rules/utils/is-supported-import.tsx +7 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Convert props syntax that is unsupported by `styled-components` <4.x to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by `styled-components`.
|
|
2
|
+
|
|
3
|
+
`styled-components` <4.x does not support having an arrow function inside a CSS value:
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
styled.div({
|
|
7
|
+
color: ({ myColor }) => myColor,
|
|
8
|
+
backgroundColor: (props) => props.someColor,
|
|
9
|
+
});
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
However, refactoring the arrow function so that it is the argument to `styled.div` will fix the issue:
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
styled.div((props) => ({
|
|
16
|
+
color: props.myColor,
|
|
17
|
+
backgroundColor: props.someColor,
|
|
18
|
+
}));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
This ESLint rule will only run on usages of the `styled` API when imported from `styled-components`.
|
|
22
|
+
|
|
23
|
+
## About the autofixer
|
|
24
|
+
|
|
25
|
+
This rule has an autofixer that will automatically perform the above arrow function refactoring for the majority of cases, including for nested selectors and any props used in template literal values.
|
|
26
|
+
|
|
27
|
+
However, there are a few situations where the autofixer will not be run. For these, you will need to manually fix the output, or migrate the code to `@compiled/react`.
|
|
28
|
+
|
|
29
|
+
### Type annotations
|
|
30
|
+
|
|
31
|
+
Type annotations in the arrow function are not supported; you will need to remediate the lint error manually. For example:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
type Props = {
|
|
35
|
+
myColor: string,
|
|
36
|
+
someColor: string,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
styled.div({
|
|
40
|
+
color: ({ myColor }: Props) => myColor,
|
|
41
|
+
backgroundColor: (props: Props) => props.someColor,
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
will need to be manually refactored to
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
type Props = {
|
|
49
|
+
myColor: string,
|
|
50
|
+
someColor: string,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
styled.div((props: Props) => ({
|
|
54
|
+
color: props.myColor,
|
|
55
|
+
backgroundColor: props.someColor,
|
|
56
|
+
}));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Special syntax in the arrow function parameter(s)
|
|
60
|
+
|
|
61
|
+
Rest elements, default values, and so on in the parameter of an arrow function will need to be remediated manually. For example:
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
styled.div({
|
|
65
|
+
color: ({ myColor = '#fff' }) => myColor,
|
|
66
|
+
backgroundColor: ({ myColor = '#aaa' }) => myColor,
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
could potentially be remediated with
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
styled.div((props) => ({
|
|
74
|
+
color: myColor ?? '#fff',
|
|
75
|
+
backgroundColor: myColor ?? '#aaa',
|
|
76
|
+
}));
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
### Incorrect
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import styled from 'styled-components';
|
|
85
|
+
|
|
86
|
+
styled.div({
|
|
87
|
+
color: ({ myColor }) => myColor,
|
|
88
|
+
backgroundColor: (props) => props.someColor,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
styled.div({
|
|
92
|
+
color: `url(/tmp/${({ coolProp }) => coolProp}.png)`,
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Correct
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
import styled from 'styled-components';
|
|
100
|
+
|
|
101
|
+
styled.div((props) => ({
|
|
102
|
+
color: props.myColor,
|
|
103
|
+
backgroundColor: props.someColor,
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
styled.div((props) => ({
|
|
107
|
+
color: url(`/tmp/${coolProp}.png`),
|
|
108
|
+
}));
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## When not to use it
|
|
112
|
+
|
|
113
|
+
You do not need this rule if you are not using a codebase that has an old version of `styled-components` (<4.x).
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
invalid: [
|
|
11
|
+
// ESLint rule shouldn't try to fix all of the test cases below, which are
|
|
12
|
+
// erroneous and invalid. But we should still report an error nonetheless.
|
|
13
|
+
|
|
14
|
+
{
|
|
15
|
+
name: 'disables autofixer when two arguments in arrow function (with destructured props)',
|
|
16
|
+
code: `
|
|
17
|
+
import styled from 'styled-components';
|
|
18
|
+
|
|
19
|
+
styled.div({
|
|
20
|
+
color: ({ customColor }, anotherVariable) => customColor,
|
|
21
|
+
});
|
|
22
|
+
`,
|
|
23
|
+
errors: [
|
|
24
|
+
{
|
|
25
|
+
messageId: 'unsupported-styled-components-prop-syntax-no-autofixer',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'disables autofixer when two arguments in arrow function (with props argument)',
|
|
31
|
+
code: `
|
|
32
|
+
import styled from 'styled-components';
|
|
33
|
+
|
|
34
|
+
styled.div({
|
|
35
|
+
color: (oneVariable, anotherVariable) => oneVariable.color,
|
|
36
|
+
});
|
|
37
|
+
`,
|
|
38
|
+
errors: [
|
|
39
|
+
{
|
|
40
|
+
messageId: 'unsupported-styled-components-prop-syntax-no-autofixer',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "disables autofixer when props argument doesn't match",
|
|
46
|
+
code: `
|
|
47
|
+
import styled from 'styled-components';
|
|
48
|
+
|
|
49
|
+
styled.div({
|
|
50
|
+
backgroundColor: (props) => myProps.customColor,
|
|
51
|
+
});
|
|
52
|
+
`,
|
|
53
|
+
errors: [
|
|
54
|
+
{
|
|
55
|
+
messageId: 'unsupported-styled-components-prop-syntax-no-autofixer',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "disables autofixer when destructured props don't match",
|
|
61
|
+
code: `
|
|
62
|
+
import styled from 'styled-components';
|
|
63
|
+
|
|
64
|
+
styled.div({
|
|
65
|
+
backgroundColor: ({ customColor }) => otherColor,
|
|
66
|
+
});
|
|
67
|
+
`,
|
|
68
|
+
errors: [
|
|
69
|
+
{
|
|
70
|
+
messageId: 'unsupported-styled-components-prop-syntax-no-autofixer',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
);
|
|
@@ -0,0 +1,422 @@
|
|
|
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 styled-components usages already using supported props syntax (with logical operator)',
|
|
22
|
+
code: `
|
|
23
|
+
import styled from 'styled-components';
|
|
24
|
+
|
|
25
|
+
styled.div((props) => ({
|
|
26
|
+
color: props => props.color || 'red',
|
|
27
|
+
}));
|
|
28
|
+
`,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'ignores styled-components usages using supported props syntax (with multiple properties)',
|
|
32
|
+
code: `
|
|
33
|
+
import styled from 'styled-components';
|
|
34
|
+
|
|
35
|
+
styled.div((props) => ({
|
|
36
|
+
color: props.color,
|
|
37
|
+
backgroundColor: props.backgroundColor,
|
|
38
|
+
}));
|
|
39
|
+
`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'ignores compiled usages (props argument)',
|
|
43
|
+
code: `
|
|
44
|
+
import { styled } from '@compiled/react';
|
|
45
|
+
|
|
46
|
+
styled.div({
|
|
47
|
+
color: (props) => props.color,
|
|
48
|
+
backgroundColor: (props) => props.backgroundColor,
|
|
49
|
+
});
|
|
50
|
+
`,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'ignores compiled usages (destructured props)',
|
|
54
|
+
code: `
|
|
55
|
+
import { styled } from '@compiled/react';
|
|
56
|
+
|
|
57
|
+
styled.div({
|
|
58
|
+
color: ({ color }) => color,
|
|
59
|
+
backgroundColor: ({ backgroundColor }) => backgroundColor,
|
|
60
|
+
});
|
|
61
|
+
`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'ignores compiled usages (styled-components style syntax)',
|
|
65
|
+
code: `
|
|
66
|
+
import { styled } from '@compiled/react';
|
|
67
|
+
|
|
68
|
+
styled.div((props) => ({
|
|
69
|
+
color: props.color,
|
|
70
|
+
backgroundColor: props.backgroundColor,
|
|
71
|
+
}));
|
|
72
|
+
`,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'ignores template literals passed to styled-components',
|
|
76
|
+
code: `
|
|
77
|
+
import { styled } from 'styled-components';
|
|
78
|
+
|
|
79
|
+
const someStyles = \`border-radius: \${token('border.radius', '3px')};\`;
|
|
80
|
+
|
|
81
|
+
styled.div(someStyles);
|
|
82
|
+
`,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'ignores token function passed to styled-components',
|
|
86
|
+
code: `
|
|
87
|
+
import styled from 'styled-components';
|
|
88
|
+
import { token } from 'some-package';
|
|
89
|
+
import { someFallback } from 'other-package';
|
|
90
|
+
|
|
91
|
+
styled.div({
|
|
92
|
+
color: token('some-token', someFallback),
|
|
93
|
+
});
|
|
94
|
+
`,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
invalid: [
|
|
98
|
+
{
|
|
99
|
+
name: 'converts styled-components props argument',
|
|
100
|
+
code: `
|
|
101
|
+
import styled from 'styled-components';
|
|
102
|
+
|
|
103
|
+
styled.div({
|
|
104
|
+
color: (props) => props.color,
|
|
105
|
+
backgroundColor: (props) => props.backgroundColor,
|
|
106
|
+
});
|
|
107
|
+
`,
|
|
108
|
+
output: `
|
|
109
|
+
import styled from 'styled-components';
|
|
110
|
+
|
|
111
|
+
styled.div((props) => ({
|
|
112
|
+
color: props.color,
|
|
113
|
+
backgroundColor: props.backgroundColor,
|
|
114
|
+
}));
|
|
115
|
+
`,
|
|
116
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'converts styled-components destructured props',
|
|
120
|
+
code: `
|
|
121
|
+
import styled from 'styled-components';
|
|
122
|
+
|
|
123
|
+
styled.div({
|
|
124
|
+
color: ({ color }) => color,
|
|
125
|
+
backgroundColor: ({ backgroundColor }) => backgroundColor,
|
|
126
|
+
});
|
|
127
|
+
`,
|
|
128
|
+
output: `
|
|
129
|
+
import styled from 'styled-components';
|
|
130
|
+
|
|
131
|
+
styled.div((props) => ({
|
|
132
|
+
color: props.color,
|
|
133
|
+
backgroundColor: props.backgroundColor,
|
|
134
|
+
}));
|
|
135
|
+
`,
|
|
136
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'converts mixture of props argument and destructured props',
|
|
140
|
+
code: `
|
|
141
|
+
import styled from 'styled-components';
|
|
142
|
+
|
|
143
|
+
styled.div({
|
|
144
|
+
color: ({ color }) => color,
|
|
145
|
+
backgroundColor: (props) => props.backgroundColor,
|
|
146
|
+
});
|
|
147
|
+
`,
|
|
148
|
+
output: `
|
|
149
|
+
import styled from 'styled-components';
|
|
150
|
+
|
|
151
|
+
styled.div((props) => ({
|
|
152
|
+
color: props.color,
|
|
153
|
+
backgroundColor: props.backgroundColor,
|
|
154
|
+
}));
|
|
155
|
+
`,
|
|
156
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: 'converts mix of valid props syntax and invalid props syntax',
|
|
160
|
+
code: `
|
|
161
|
+
import styled from 'styled-components';
|
|
162
|
+
|
|
163
|
+
styled.div(
|
|
164
|
+
(props) => ({
|
|
165
|
+
color: props.color,
|
|
166
|
+
backgroundColor: props.backgroundColor,
|
|
167
|
+
}),
|
|
168
|
+
{
|
|
169
|
+
height: (props) => props.height,
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
`,
|
|
173
|
+
output: `
|
|
174
|
+
import styled from 'styled-components';
|
|
175
|
+
|
|
176
|
+
styled.div(
|
|
177
|
+
(props) => ({
|
|
178
|
+
color: props.color,
|
|
179
|
+
backgroundColor: props.backgroundColor,
|
|
180
|
+
}),
|
|
181
|
+
(props) => ({
|
|
182
|
+
height: props.height,
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
`,
|
|
186
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'converts mix of renamed props argument and destructured props',
|
|
190
|
+
code: `
|
|
191
|
+
import styled from 'styled-components';
|
|
192
|
+
|
|
193
|
+
styled.div({
|
|
194
|
+
color: ({ customColor }) => customColor,
|
|
195
|
+
backgroundColor: (myProps) => myProps.backgroundColor,
|
|
196
|
+
height: (props) => props.customHeight,
|
|
197
|
+
});
|
|
198
|
+
`,
|
|
199
|
+
output: `
|
|
200
|
+
import styled from 'styled-components';
|
|
201
|
+
|
|
202
|
+
styled.div((props) => ({
|
|
203
|
+
color: props.customColor,
|
|
204
|
+
backgroundColor: props.backgroundColor,
|
|
205
|
+
height: props.customHeight,
|
|
206
|
+
}));
|
|
207
|
+
`,
|
|
208
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: 'converts props with same name',
|
|
212
|
+
code: `
|
|
213
|
+
import styled from 'styled-components';
|
|
214
|
+
|
|
215
|
+
styled.div({
|
|
216
|
+
color: ({ customColor }) => customColor,
|
|
217
|
+
backgroundColor: (myProps) => myProps.customColor,
|
|
218
|
+
height: (props) => props.customHeight,
|
|
219
|
+
});
|
|
220
|
+
`,
|
|
221
|
+
output: `
|
|
222
|
+
import styled from 'styled-components';
|
|
223
|
+
|
|
224
|
+
styled.div((props) => ({
|
|
225
|
+
color: props.customColor,
|
|
226
|
+
backgroundColor: props.customColor,
|
|
227
|
+
height: props.customHeight,
|
|
228
|
+
}));
|
|
229
|
+
`,
|
|
230
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: 'converts props with same name (variant two)',
|
|
234
|
+
code: `
|
|
235
|
+
import styled from 'styled-components';
|
|
236
|
+
|
|
237
|
+
styled.div({
|
|
238
|
+
color: ({ customColor }) => customColor,
|
|
239
|
+
backgroundColor: ({ customColor }) => customColor,
|
|
240
|
+
height: (props) => props.customHeight,
|
|
241
|
+
});
|
|
242
|
+
`,
|
|
243
|
+
output: `
|
|
244
|
+
import styled from 'styled-components';
|
|
245
|
+
|
|
246
|
+
styled.div((props) => ({
|
|
247
|
+
color: props.customColor,
|
|
248
|
+
backgroundColor: props.customColor,
|
|
249
|
+
height: props.customHeight,
|
|
250
|
+
}));
|
|
251
|
+
`,
|
|
252
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: 'converts props with same name (variant three)',
|
|
256
|
+
code: `
|
|
257
|
+
import styled from 'styled-components';
|
|
258
|
+
|
|
259
|
+
styled.div({
|
|
260
|
+
color: (props) => props.customColor,
|
|
261
|
+
backgroundColor: (props) => props.customColor,
|
|
262
|
+
height: (props) => props.customHeight,
|
|
263
|
+
});
|
|
264
|
+
`,
|
|
265
|
+
output: `
|
|
266
|
+
import styled from 'styled-components';
|
|
267
|
+
|
|
268
|
+
styled.div((props) => ({
|
|
269
|
+
color: props.customColor,
|
|
270
|
+
backgroundColor: props.customColor,
|
|
271
|
+
height: props.customHeight,
|
|
272
|
+
}));
|
|
273
|
+
`,
|
|
274
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
name: 'converts props inside template literal',
|
|
278
|
+
code: `
|
|
279
|
+
import styled from 'styled-components';
|
|
280
|
+
|
|
281
|
+
styled.div({
|
|
282
|
+
backgroundImage: \`url(\${({ src }) => src})\`,
|
|
283
|
+
backgroundSize: 'cover',
|
|
284
|
+
});
|
|
285
|
+
`,
|
|
286
|
+
output: `
|
|
287
|
+
import styled from 'styled-components';
|
|
288
|
+
|
|
289
|
+
styled.div((props) => ({
|
|
290
|
+
backgroundImage: \`url(\${props.src})\`,
|
|
291
|
+
backgroundSize: 'cover',
|
|
292
|
+
}));
|
|
293
|
+
`,
|
|
294
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: 'converts props with complicated expressions',
|
|
298
|
+
code: `
|
|
299
|
+
import styled from 'styled-components';
|
|
300
|
+
|
|
301
|
+
styled.div({
|
|
302
|
+
height: ({ height, width }) => height + width,
|
|
303
|
+
width: ({ height }) => height,
|
|
304
|
+
padding: ({ width }) => \`\${width}px \${width + 3}px \${width + 2}px\`,
|
|
305
|
+
});
|
|
306
|
+
`,
|
|
307
|
+
output: `
|
|
308
|
+
import styled from 'styled-components';
|
|
309
|
+
|
|
310
|
+
styled.div((props) => ({
|
|
311
|
+
height: props.height + props.width,
|
|
312
|
+
width: props.height,
|
|
313
|
+
padding: \`\${props.width}px \${props.width + 3}px \${props.width + 2}px\`,
|
|
314
|
+
}));
|
|
315
|
+
`,
|
|
316
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: 'converts props with overlapping names',
|
|
320
|
+
code: `
|
|
321
|
+
import styled from 'styled-components';
|
|
322
|
+
|
|
323
|
+
styled.div({
|
|
324
|
+
height: ({ height, newHeight, oldHeight }) => height + newHeight / oldHeight,
|
|
325
|
+
width: ({ height, oldHeight }) => height + oldHeight,
|
|
326
|
+
});
|
|
327
|
+
`,
|
|
328
|
+
output: `
|
|
329
|
+
import styled from 'styled-components';
|
|
330
|
+
|
|
331
|
+
styled.div((props) => ({
|
|
332
|
+
height: props.height + props.newHeight / props.oldHeight,
|
|
333
|
+
width: props.height + props.oldHeight,
|
|
334
|
+
}));
|
|
335
|
+
`,
|
|
336
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
name: 'converts props mixed with token function',
|
|
340
|
+
code: `
|
|
341
|
+
import styled from 'styled-components';
|
|
342
|
+
import { someFallback } from 'some-package';
|
|
343
|
+
|
|
344
|
+
styled.div({
|
|
345
|
+
padding: ({ myPadding }) => \`\${token('some-token', someFallback)} \${myPadding}\`,
|
|
346
|
+
});
|
|
347
|
+
`,
|
|
348
|
+
output: `
|
|
349
|
+
import styled from 'styled-components';
|
|
350
|
+
import { someFallback } from 'some-package';
|
|
351
|
+
|
|
352
|
+
styled.div((props) => ({
|
|
353
|
+
padding: \`\${token('some-token', someFallback)} \${props.myPadding}\`,
|
|
354
|
+
}));
|
|
355
|
+
`,
|
|
356
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
name: 'converts mix of styled variable arguments and object arguments',
|
|
360
|
+
code: `
|
|
361
|
+
import styled from 'styled-components';
|
|
362
|
+
import { someFallback } from 'some-package';
|
|
363
|
+
|
|
364
|
+
const someVariable = {
|
|
365
|
+
color: 'blue',
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
styled.div(
|
|
369
|
+
someVariable,
|
|
370
|
+
css\`
|
|
371
|
+
color: 'pink';
|
|
372
|
+
\`,
|
|
373
|
+
{
|
|
374
|
+
height: ({ myHeight }) => \`\${myHeight + 5}px\`,
|
|
375
|
+
}
|
|
376
|
+
);
|
|
377
|
+
`,
|
|
378
|
+
output: `
|
|
379
|
+
import styled from 'styled-components';
|
|
380
|
+
import { someFallback } from 'some-package';
|
|
381
|
+
|
|
382
|
+
const someVariable = {
|
|
383
|
+
color: 'blue',
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
styled.div(
|
|
387
|
+
someVariable,
|
|
388
|
+
css\`
|
|
389
|
+
color: 'pink';
|
|
390
|
+
\`,
|
|
391
|
+
(props) => ({
|
|
392
|
+
height: \`\${props.myHeight + 5}px\`,
|
|
393
|
+
})
|
|
394
|
+
);
|
|
395
|
+
`,
|
|
396
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
name: 'converts mix of props and non-props',
|
|
400
|
+
code: `
|
|
401
|
+
import styled from 'styled-components';
|
|
402
|
+
|
|
403
|
+
styled.div({
|
|
404
|
+
padding: '5px',
|
|
405
|
+
width: ({ myWidth }) => myWidth,
|
|
406
|
+
margin: \`2px \${token('some-token')}\`
|
|
407
|
+
});
|
|
408
|
+
`,
|
|
409
|
+
output: `
|
|
410
|
+
import styled from 'styled-components';
|
|
411
|
+
|
|
412
|
+
styled.div((props) => ({
|
|
413
|
+
padding: '5px',
|
|
414
|
+
width: props.myWidth,
|
|
415
|
+
margin: \`2px \${token('some-token')}\`
|
|
416
|
+
}));
|
|
417
|
+
`,
|
|
418
|
+
errors: [{ messageId: 'unsupported-styled-components-prop-syntax' }],
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
);
|