@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.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 +17 -0
- package/constellation/consistent-css-prop-usage/usage.mdx +3 -1
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/constellation/no-css-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-empty-styled-expression/usage.mdx +5 -2
- package/constellation/no-exported-css/usage.mdx +5 -2
- package/constellation/no-exported-keyframes/usage.mdx +5 -2
- package/constellation/no-invalid-css-map/usage.mdx +5 -2
- package/constellation/no-js-xcss/usage.mdx +3 -1
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-suppress-xcss/usage.mdx +6 -3
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +141 -128
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +133 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
This rule enforces passing dynamic CSS values to the `style` prop in JSX components.
|
|
2
2
|
|
|
3
|
-
We only want `props.style` to be used for dynamic values that cannot be easily determined at build
|
|
3
|
+
We only want `props.style` to be used for dynamic values that cannot be easily determined at build
|
|
4
|
+
time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any
|
|
5
|
+
other statically analysable values should be passed to the `style` attribute. Instead, static CSS
|
|
6
|
+
values should be passed into the `css` prop in JSX components.
|
|
4
7
|
|
|
5
8
|
## Examples
|
|
6
9
|
|
|
@@ -8,14 +11,14 @@ We only want `props.style` to be used for dynamic values that cannot be easily d
|
|
|
8
11
|
|
|
9
12
|
```tsx
|
|
10
13
|
function Component() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
return (
|
|
15
|
+
<div
|
|
16
|
+
style={{
|
|
17
|
+
margin: 0,
|
|
18
|
+
color: 'red',
|
|
19
|
+
}}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
19
22
|
}
|
|
20
23
|
```
|
|
21
24
|
|
|
@@ -23,14 +26,14 @@ function Component() {
|
|
|
23
26
|
|
|
24
27
|
```tsx
|
|
25
28
|
function Component(props) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
style={{
|
|
32
|
+
width: props.width,
|
|
33
|
+
'--my-nested-width': props.width,
|
|
34
|
+
}}
|
|
35
|
+
css={css({ margin: 0, color: 'red' })}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
35
38
|
}
|
|
36
39
|
```
|
|
@@ -2,16 +2,16 @@ import { tester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
tester.run('enforce-style-prop', rule, {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
name: 'No style attribute used',
|
|
8
|
+
code: `
|
|
9
9
|
<div css={styles} />
|
|
10
10
|
`,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'Values from props are acceptable',
|
|
14
|
+
code: `
|
|
15
15
|
function Component(props) {
|
|
16
16
|
return <div
|
|
17
17
|
style={{
|
|
@@ -22,26 +22,26 @@ tester.run('enforce-style-prop', rule, {
|
|
|
22
22
|
/>
|
|
23
23
|
}
|
|
24
24
|
`,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Values from deconstructed props are acceptable',
|
|
28
|
+
code: `
|
|
29
29
|
function DeconstructionComponent1({ myWidth }) {
|
|
30
30
|
return <div style={{ width: myWidth }}>hello</div>;
|
|
31
31
|
}
|
|
32
32
|
`,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'Multiple values from deconstructed props are acceptable',
|
|
36
|
+
code: `
|
|
37
37
|
function DeconstructionComponent2({ myWidth, height, myColor = '#fff' }) {
|
|
38
38
|
return <div style={{ width: myWidth, height, color: myColor }}>hello</div>;
|
|
39
39
|
}
|
|
40
40
|
`,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'Skips linting @media query as it is not supported by the style prop anyways',
|
|
44
|
+
code: `
|
|
45
45
|
function Component() {
|
|
46
46
|
return <div
|
|
47
47
|
style={{
|
|
@@ -50,10 +50,10 @@ tester.run('enforce-style-prop', rule, {
|
|
|
50
50
|
/>
|
|
51
51
|
}
|
|
52
52
|
`,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'Skips linting selector as it is not supported by the style prop anyways',
|
|
56
|
+
code: `
|
|
57
57
|
function Component() {
|
|
58
58
|
return <div
|
|
59
59
|
style={{
|
|
@@ -62,10 +62,10 @@ tester.run('enforce-style-prop', rule, {
|
|
|
62
62
|
/>
|
|
63
63
|
}
|
|
64
64
|
`,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'Static styles are outside of style attribute',
|
|
68
|
+
code: `
|
|
69
69
|
function Component(props) {
|
|
70
70
|
return (
|
|
71
71
|
<div
|
|
@@ -77,37 +77,37 @@ tester.run('enforce-style-prop', rule, {
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
`,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'Props destructured in function via object pattern',
|
|
83
|
+
code: `
|
|
84
84
|
function Component(props) {
|
|
85
85
|
const { width } = props;
|
|
86
86
|
return <div style={{ width: width }} />
|
|
87
87
|
}
|
|
88
88
|
`,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'Props destructured in function via member expression',
|
|
92
|
+
code: `
|
|
93
93
|
function Component(props) {
|
|
94
94
|
const width = props.width;
|
|
95
95
|
return <div style={{ width: width }} />
|
|
96
96
|
}
|
|
97
97
|
`,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'Ignore state variables',
|
|
101
|
+
code: `
|
|
102
102
|
const Component = () => {
|
|
103
103
|
const [state, setState] = useState();
|
|
104
104
|
return <div style={{ width: state.width }} />
|
|
105
105
|
};
|
|
106
106
|
`,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: 'Ignore variables initialised by call expression',
|
|
110
|
+
code: `
|
|
111
111
|
const Component = () => {
|
|
112
112
|
const tableWidth = calcDefaultLayoutWidthByAppearance(
|
|
113
113
|
rendererAppearance,
|
|
@@ -118,10 +118,10 @@ tester.run('enforce-style-prop', rule, {
|
|
|
118
118
|
)
|
|
119
119
|
}
|
|
120
120
|
`,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'Property from object initialisation is ok',
|
|
124
|
+
code: `
|
|
125
125
|
function Component(props) {
|
|
126
126
|
const obj = { width: 0 };
|
|
127
127
|
return <div
|
|
@@ -131,10 +131,10 @@ tester.run('enforce-style-prop', rule, {
|
|
|
131
131
|
/>
|
|
132
132
|
}
|
|
133
133
|
`,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'Let variables are ok',
|
|
137
|
+
code: `
|
|
138
138
|
function Component(props) {
|
|
139
139
|
let width = 0;
|
|
140
140
|
return <div
|
|
@@ -144,10 +144,10 @@ tester.run('enforce-style-prop', rule, {
|
|
|
144
144
|
/>
|
|
145
145
|
}
|
|
146
146
|
`,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'Ignore function calls',
|
|
150
|
+
code: `
|
|
151
151
|
import { calcDefaultLayoutWidthByAppearance } from '../shared';
|
|
152
152
|
const Component = () => {
|
|
153
153
|
return (
|
|
@@ -162,12 +162,12 @@ tester.run('enforce-style-prop', rule, {
|
|
|
162
162
|
);
|
|
163
163
|
};
|
|
164
164
|
`,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
invalid: [
|
|
168
|
+
{
|
|
169
|
+
name: 'Basic test for static css values',
|
|
170
|
+
code: `
|
|
171
171
|
function Component(props) {
|
|
172
172
|
return <div
|
|
173
173
|
style={{
|
|
@@ -177,14 +177,11 @@ tester.run('enforce-style-prop', rule, {
|
|
|
177
177
|
/>
|
|
178
178
|
}
|
|
179
179
|
`,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
{
|
|
186
|
-
name: 'No constants passed to style',
|
|
187
|
-
code: `
|
|
180
|
+
errors: [{ messageId: 'enforce-style-prop' }, { messageId: 'enforce-style-prop' }],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'No constants passed to style',
|
|
184
|
+
code: `
|
|
188
185
|
function Component(props) {
|
|
189
186
|
const color = 'red';
|
|
190
187
|
return <div
|
|
@@ -194,11 +191,11 @@ tester.run('enforce-style-prop', rule, {
|
|
|
194
191
|
/>
|
|
195
192
|
}
|
|
196
193
|
`,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
194
|
+
errors: [{ messageId: 'enforce-style-prop' }],
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'No spread operator within style',
|
|
198
|
+
code: `
|
|
202
199
|
import importedStyleObj from '../shared';
|
|
203
200
|
function Component(props) {
|
|
204
201
|
const color = 'red';
|
|
@@ -210,40 +207,37 @@ tester.run('enforce-style-prop', rule, {
|
|
|
210
207
|
/>
|
|
211
208
|
}
|
|
212
209
|
`,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
name: 'No imported object passed to style',
|
|
220
|
-
code: `
|
|
210
|
+
errors: [{ messageId: 'enforce-style-prop' }, { messageId: 'enforce-style-prop' }],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'No imported object passed to style',
|
|
214
|
+
code: `
|
|
221
215
|
import importedStyleObj from '../shared';
|
|
222
216
|
function AnotherComponent() {
|
|
223
217
|
return <div style={importedStyleObj} />;
|
|
224
218
|
}
|
|
225
219
|
`,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
220
|
+
errors: [{ messageId: 'enforce-style-prop' }],
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: 'No rest prop',
|
|
224
|
+
code: `
|
|
231
225
|
function Component({ prop1, ...spreadElement }) {
|
|
232
226
|
return <div style={{ 'button': spreadElement }}>hello</div>
|
|
233
227
|
}
|
|
234
228
|
`,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
229
|
+
errors: [{ messageId: 'enforce-style-prop' }],
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'No token calls',
|
|
233
|
+
code: `
|
|
240
234
|
import { token } from '@atlaskit/tokens';
|
|
241
235
|
|
|
242
236
|
function Component() {
|
|
243
237
|
return <div style={{ paddingBottom: token('space.150', '12px') }} />;
|
|
244
238
|
}
|
|
245
239
|
`,
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
240
|
+
errors: [{ messageId: 'enforce-style-prop' }],
|
|
241
|
+
},
|
|
242
|
+
],
|
|
249
243
|
});
|