@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,4 +1,5 @@
|
|
|
1
|
-
This rule prevents the usage of the nested selectors in style declarations. Avoid setting styles for
|
|
1
|
+
This rule prevents the usage of the nested selectors in style declarations. Avoid setting styles for
|
|
2
|
+
any child elements or elements that require context from other elements.
|
|
2
3
|
|
|
3
4
|
## Examples
|
|
4
5
|
|
|
@@ -7,27 +8,27 @@ This rule prevents the usage of the nested selectors in style declarations. Avoi
|
|
|
7
8
|
```js
|
|
8
9
|
import { css } from '@compiled/react';
|
|
9
10
|
const styles = css({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
h2: {
|
|
12
|
+
fontSize: '1.5rem',
|
|
13
|
+
},
|
|
13
14
|
});
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
```js
|
|
17
18
|
import { styled } from '@compiled/react';
|
|
18
19
|
const Component = styled.div({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
'*': {
|
|
21
|
+
padding: 0,
|
|
22
|
+
},
|
|
22
23
|
});
|
|
23
24
|
```
|
|
24
25
|
|
|
25
26
|
```js
|
|
26
27
|
import { styled } from '@compiled/react';
|
|
27
28
|
const Component = styled.div({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
'.myclass': {
|
|
30
|
+
padding: 0,
|
|
31
|
+
},
|
|
31
32
|
});
|
|
32
33
|
```
|
|
33
34
|
|
|
@@ -36,8 +37,8 @@ const Component = styled.div({
|
|
|
36
37
|
```js
|
|
37
38
|
import { css } from '@compiled/react';
|
|
38
39
|
const styles = css({
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
display: 'flex',
|
|
41
|
+
flexDirection: 'column',
|
|
41
42
|
});
|
|
42
43
|
```
|
|
43
44
|
|
|
@@ -55,4 +56,5 @@ By default, this rule will check `css` usages from:
|
|
|
55
56
|
- `@emotion/styled`
|
|
56
57
|
- `styled-components`
|
|
57
58
|
|
|
58
|
-
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
59
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
60
|
+
array of package names (strings).
|
|
@@ -2,34 +2,34 @@ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
typescriptEslintTester.run(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
'no-nested-selectors',
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
rule,
|
|
8
|
+
{
|
|
9
|
+
valid: [
|
|
10
|
+
{
|
|
11
|
+
name: 'Basic valid test',
|
|
12
|
+
code: `
|
|
13
13
|
import { css } from '@compiled/react';
|
|
14
14
|
const styles = css({
|
|
15
15
|
display: 'flex',
|
|
16
16
|
flexDirection: 'column',
|
|
17
17
|
});
|
|
18
18
|
`,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'Basic valid test using emotion',
|
|
22
|
+
code: `
|
|
23
23
|
import styled from '@emotion/styled';
|
|
24
24
|
const Container = styled.div({
|
|
25
25
|
display: 'flex',
|
|
26
26
|
flexDirection: 'column'
|
|
27
27
|
})
|
|
28
28
|
`,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'Custom import sources (subtractive)',
|
|
32
|
+
code: `
|
|
33
33
|
import { css } from '@compiled/react';
|
|
34
34
|
const styles = css({
|
|
35
35
|
h2: {
|
|
@@ -37,15 +37,15 @@ typescriptEslintTester.run(
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
`,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
options: [
|
|
41
|
+
{
|
|
42
|
+
importSources: [],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'Styled div with no selectors',
|
|
48
|
+
code: `
|
|
49
49
|
import { styled } from '@compiled/react';
|
|
50
50
|
const Component = styled.div({
|
|
51
51
|
padding: 0,
|
|
@@ -54,10 +54,10 @@ typescriptEslintTester.run(
|
|
|
54
54
|
boxSizing: 'border-box',
|
|
55
55
|
});
|
|
56
56
|
`,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'Pseudo element selectors',
|
|
60
|
+
code: `
|
|
61
61
|
import { styled } from '@compiled/react';
|
|
62
62
|
const Component = styled.div({
|
|
63
63
|
'&:hover': {
|
|
@@ -71,10 +71,10 @@ typescriptEslintTester.run(
|
|
|
71
71
|
},
|
|
72
72
|
});
|
|
73
73
|
`,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Skips @ queries',
|
|
77
|
+
code: `
|
|
78
78
|
import { css } from '@compiled/react';
|
|
79
79
|
const styles = css({
|
|
80
80
|
'@container (width > 400px)': {
|
|
@@ -86,12 +86,12 @@ typescriptEslintTester.run(
|
|
|
86
86
|
},
|
|
87
87
|
});
|
|
88
88
|
`,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
invalid: [
|
|
92
|
+
{
|
|
93
|
+
name: 'Universal selector',
|
|
94
|
+
code: `
|
|
95
95
|
import { styled } from '@compiled/react';
|
|
96
96
|
const Component = styled.div({
|
|
97
97
|
'*': {
|
|
@@ -99,11 +99,11 @@ typescriptEslintTester.run(
|
|
|
99
99
|
}
|
|
100
100
|
});
|
|
101
101
|
`,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'Class selector',
|
|
106
|
+
code: `
|
|
107
107
|
import { styled } from '@compiled/react';
|
|
108
108
|
const Component = styled.div({
|
|
109
109
|
'.myclass': {
|
|
@@ -111,11 +111,11 @@ typescriptEslintTester.run(
|
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
113
|
`,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'ID selector',
|
|
118
|
+
code: `
|
|
119
119
|
import { styled } from '@compiled/react';
|
|
120
120
|
const Component = styled.div({
|
|
121
121
|
'#myid': {
|
|
@@ -123,11 +123,11 @@ typescriptEslintTester.run(
|
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
`,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'HTML element selector',
|
|
130
|
+
code: `
|
|
131
131
|
import { styled } from '@compiled/react';
|
|
132
132
|
const Component = styled.div({
|
|
133
133
|
h2: {
|
|
@@ -135,11 +135,11 @@ typescriptEslintTester.run(
|
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
`,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'Data-component-selector',
|
|
142
|
+
code: `
|
|
143
143
|
import { styled } from '@compiled/react';
|
|
144
144
|
const Component = styled.div({
|
|
145
145
|
'[data-component-selector="my.button"]': {
|
|
@@ -147,11 +147,11 @@ typescriptEslintTester.run(
|
|
|
147
147
|
},
|
|
148
148
|
});
|
|
149
149
|
`,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: 'Grouping selector',
|
|
154
|
+
code: `
|
|
155
155
|
import { styled } from '@compiled/react';
|
|
156
156
|
const Component = styled.div({
|
|
157
157
|
'div, p, span': {
|
|
@@ -161,11 +161,11 @@ typescriptEslintTester.run(
|
|
|
161
161
|
backgroundColor: 'red',
|
|
162
162
|
});
|
|
163
163
|
`,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'Selector including a variable',
|
|
168
|
+
code: `
|
|
169
169
|
import { styled } from '@compiled/react';
|
|
170
170
|
styled.div({
|
|
171
171
|
[\`\${SOME_VAR} > *\`]: {
|
|
@@ -173,11 +173,11 @@ typescriptEslintTester.run(
|
|
|
173
173
|
},
|
|
174
174
|
});
|
|
175
175
|
`,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'Current element selector',
|
|
180
|
+
code: `
|
|
181
181
|
import { styled } from '@compiled/react';
|
|
182
182
|
styled.div({
|
|
183
183
|
color: 'darkorchid',
|
|
@@ -186,11 +186,11 @@ typescriptEslintTester.run(
|
|
|
186
186
|
}
|
|
187
187
|
});
|
|
188
188
|
`,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'Child combinator',
|
|
193
|
+
code: `
|
|
194
194
|
import { styled } from '@compiled/react';
|
|
195
195
|
styled.div({
|
|
196
196
|
'& > &': {
|
|
@@ -198,11 +198,11 @@ typescriptEslintTester.run(
|
|
|
198
198
|
}
|
|
199
199
|
});
|
|
200
200
|
`,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
201
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: 'Child combinator without whitespace',
|
|
205
|
+
code: `
|
|
206
206
|
import { styled } from '@compiled/react';
|
|
207
207
|
styled.div({
|
|
208
208
|
'&>a': {
|
|
@@ -210,11 +210,11 @@ typescriptEslintTester.run(
|
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
212
|
`,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
213
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: 'Column combinator',
|
|
217
|
+
code: `
|
|
218
218
|
import { styled } from '@compiled/react';
|
|
219
219
|
styled.div({
|
|
220
220
|
'col.selected||td': {
|
|
@@ -222,11 +222,11 @@ typescriptEslintTester.run(
|
|
|
222
222
|
}
|
|
223
223
|
});
|
|
224
224
|
`,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
225
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: 'Namespace selector',
|
|
229
|
+
code: `
|
|
230
230
|
import { styled } from '@compiled/react';
|
|
231
231
|
styled.div({
|
|
232
232
|
'myNameSpace|a': {
|
|
@@ -234,11 +234,11 @@ typescriptEslintTester.run(
|
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
`,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
237
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: 'Descendant combinator',
|
|
241
|
+
code: `
|
|
242
242
|
import { styled } from '@compiled/react';
|
|
243
243
|
const Component = styled.div({
|
|
244
244
|
'& &:hover': {
|
|
@@ -246,11 +246,11 @@ typescriptEslintTester.run(
|
|
|
246
246
|
}
|
|
247
247
|
});
|
|
248
248
|
`,
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
249
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'cssMap API',
|
|
253
|
+
code: `
|
|
254
254
|
import { cssMap } from '@compiled/react';
|
|
255
255
|
|
|
256
256
|
const styles = cssMap({
|
|
@@ -261,11 +261,11 @@ typescriptEslintTester.run(
|
|
|
261
261
|
},
|
|
262
262
|
});
|
|
263
263
|
`,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
264
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: 'keyframes API',
|
|
268
|
+
code: `
|
|
269
269
|
import { keyframes } from '@emotion/react';
|
|
270
270
|
|
|
271
271
|
const keyFrameStyles = keyframes({
|
|
@@ -279,11 +279,11 @@ typescriptEslintTester.run(
|
|
|
279
279
|
},
|
|
280
280
|
});
|
|
281
281
|
`,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
282
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: 'Next sibling selector',
|
|
286
|
+
code: `
|
|
287
287
|
import { styled } from '@compiled/react';
|
|
288
288
|
styled.div({
|
|
289
289
|
'&+a': {
|
|
@@ -291,11 +291,11 @@ typescriptEslintTester.run(
|
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
`,
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
294
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: 'Next sibling selector on non-HTML element',
|
|
298
|
+
code: `
|
|
299
299
|
import { styled } from '@compiled/react';
|
|
300
300
|
styled.div({
|
|
301
301
|
'& + &': {
|
|
@@ -303,11 +303,11 @@ typescriptEslintTester.run(
|
|
|
303
303
|
}
|
|
304
304
|
});
|
|
305
305
|
`,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: 'Subsequent sibling selector on non-HTML element',
|
|
310
|
+
code: `
|
|
311
311
|
import { styled } from '@compiled/react';
|
|
312
312
|
styled.div({
|
|
313
313
|
'& ~ &': {
|
|
@@ -315,8 +315,21 @@ typescriptEslintTester.run(
|
|
|
315
315
|
}
|
|
316
316
|
});
|
|
317
317
|
`,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
name: 'Nested selector inside styled(BaseComponent)()',
|
|
322
|
+
code: `
|
|
323
|
+
import { styled } from '@compiled/react';
|
|
324
|
+
import { BaseComponent } from './base-component';
|
|
325
|
+
styled(BaseComponent)({
|
|
326
|
+
'> span': {
|
|
327
|
+
color: 'orange'
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
`,
|
|
331
|
+
errors: [{ messageId: 'no-nested-selectors' }],
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
},
|
|
322
335
|
);
|
|
@@ -10,7 +10,7 @@ Avoid usages of styled, eg. `styled.div`, `styled('div')`, `styled(Component)`,
|
|
|
10
10
|
import styled from 'styled-components';
|
|
11
11
|
|
|
12
12
|
const Component = styled.div`
|
|
13
|
-
|
|
13
|
+
color: red;
|
|
14
14
|
`;
|
|
15
15
|
export default styled.div({ color: 'red' });
|
|
16
16
|
```
|
|
@@ -33,7 +33,7 @@ export const ComponentTwo = styled3(Component)({ … });
|
|
|
33
33
|
import styled from 'styled-components';
|
|
34
34
|
|
|
35
35
|
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
|
|
36
|
-
|
|
36
|
+
color: 'red',
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
|
|
|
41
41
|
import styled from 'styled-components';
|
|
42
42
|
|
|
43
43
|
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))`
|
|
44
|
-
|
|
44
|
+
color: red;
|
|
45
45
|
`;
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -53,7 +53,7 @@ import { css, jsx } from '@emotion/react';
|
|
|
53
53
|
const styles = css({ color: 'red' });
|
|
54
54
|
|
|
55
55
|
const Component = ({ children }) => {
|
|
56
|
-
|
|
56
|
+
return <div css={styles}>{children}</div>;
|
|
57
57
|
};
|
|
58
58
|
```
|
|
59
59
|
|
|
@@ -62,11 +62,11 @@ const Component = ({ children }) => {
|
|
|
62
62
|
import { Box, xcss } from '@atlaskit/primitives';
|
|
63
63
|
|
|
64
64
|
const styles = xcss({
|
|
65
|
-
|
|
65
|
+
color: 'color.text.subtlest',
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
const Component = ({ children }) => {
|
|
69
|
-
|
|
69
|
+
return <Box xcss={styles}>{children}</Box>;
|
|
70
70
|
};
|
|
71
71
|
```
|
|
72
72
|
|
|
@@ -74,9 +74,14 @@ const Component = ({ children }) => {
|
|
|
74
74
|
|
|
75
75
|
### Why avoid using `styled` imports?
|
|
76
76
|
|
|
77
|
-
Using `styled` imports impacts file readability, has TypeScript implications, adds linting
|
|
77
|
+
Using `styled` imports impacts file readability, has TypeScript implications, adds linting
|
|
78
|
+
complexity, promotes exported styles, and potential refactoring efforts. Using `css()` with the
|
|
79
|
+
`<div css={…}>` syntax is more performant and clear.
|
|
78
80
|
|
|
79
81
|
### How will I extend like `styled(Button)`?
|
|
80
82
|
|
|
81
|
-
Primarily, we would suggest you don't extend styles of a component you don't own unless they have an
|
|
82
|
-
|
|
83
|
+
Primarily, we would suggest you don't extend styles of a component you don't own unless they have an
|
|
84
|
+
explicit bounded interface for you to customize against. The Atlassian Design System for example has
|
|
85
|
+
removed `styled(Button)` interactivity in our latest variants because they are unsafe for us to
|
|
86
|
+
evolve the system with. Instead, make use of reusable component patterns to pass props around which
|
|
87
|
+
impact the styles of that component.
|
|
@@ -2,9 +2,9 @@ import { tester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
tester.run('no-styled', rule, {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
code: `
|
|
8
8
|
import { css, jsx } from '@emotion/react';
|
|
9
9
|
|
|
10
10
|
const styles = css({ color: 'red' });
|
|
@@ -13,9 +13,9 @@ tester.run('no-styled', rule, {
|
|
|
13
13
|
return <div css={styles}>{children}</div>;
|
|
14
14
|
};
|
|
15
15
|
`,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
code: `
|
|
19
19
|
import { Box, xcss } from '@atlaskit/primitives';
|
|
20
20
|
|
|
21
21
|
const styles = xcss({
|
|
@@ -25,49 +25,49 @@ tester.run('no-styled', rule, {
|
|
|
25
25
|
const Component = ({ children }) => {
|
|
26
26
|
return <Box xcss={styles}>{children}</Box>;
|
|
27
27
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
invalid: [
|
|
32
|
+
{
|
|
33
|
+
code: `
|
|
34
34
|
import styled from 'styled-components';
|
|
35
35
|
|
|
36
36
|
const Component = styled.div\`color: red;\`
|
|
37
37
|
`,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
errors: [{ messageId: 'no-styled' }],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
code: `
|
|
42
42
|
import styled from 'styled-components';
|
|
43
43
|
|
|
44
44
|
export default styled.div({ color: 'red' });
|
|
45
45
|
`,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
errors: [{ messageId: 'no-styled' }],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: `
|
|
50
50
|
import { styled as styled3 } from '@compiled/react';
|
|
51
51
|
|
|
52
52
|
export const ComponentTwo = styled3(Component)({ color: 'blue' });
|
|
53
53
|
`,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
errors: [{ messageId: 'no-styled' }],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
code: `
|
|
58
58
|
import styled from 'styled-components';
|
|
59
59
|
|
|
60
60
|
export default styled.div.attrs(props => ({ 'data-testid': props.testId }))({ color: 'red' });
|
|
61
61
|
`,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
errors: [{ messageId: 'no-styled' }],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
code: `
|
|
66
66
|
import styled from 'styled-components';
|
|
67
67
|
|
|
68
68
|
export default styled.div.attrs(props => ({ 'data-testid': props.testId }))\`color: red\`;
|
|
69
69
|
`,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
errors: [{ messageId: 'no-styled' }],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
73
|
});
|