@atlaskit/eslint-plugin-ui-styling-standard 0.16.2 → 0.16.4

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 (52) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/constellation/atlaskit-theme/usage.mdx +74 -55
  3. package/constellation/convert-props-syntax/usage.mdx +29 -24
  4. package/constellation/enforce-style-prop/usage.mdx +32 -26
  5. package/constellation/local-cx-xcss/usage.mdx +27 -15
  6. package/constellation/no-array-arguments/usage.mdx +12 -9
  7. package/constellation/no-classname-prop/usage.mdx +13 -5
  8. package/constellation/no-container-queries/usage.mdx +65 -16
  9. package/constellation/no-dynamic-styles/usage.mdx +16 -11
  10. package/constellation/no-exported-styles/usage.mdx +25 -30
  11. package/constellation/no-global-styles/usage.mdx +4 -3
  12. package/constellation/no-important-styles/usage.mdx +5 -3
  13. package/constellation/no-imported-style-values/usage.mdx +30 -27
  14. package/constellation/no-nested-selectors/usage.mdx +51 -18
  15. package/constellation/no-styled/usage.mdx +17 -14
  16. package/constellation/no-unsafe-selectors/usage.mdx +184 -58
  17. package/constellation/no-unsafe-values/usage.mdx +150 -48
  18. package/constellation/use-compiled/usage.mdx +8 -8
  19. package/dist/cjs/rules/no-array-arguments/index.js +3 -3
  20. package/dist/cjs/rules/no-dynamic-styles/index.js +2 -2
  21. package/dist/cjs/rules/no-imported-style-values/index.js +2 -2
  22. package/dist/cjs/rules/no-unsafe-values/index.js +2 -2
  23. package/dist/es2019/rules/no-array-arguments/index.js +2 -2
  24. package/dist/es2019/rules/no-dynamic-styles/index.js +1 -1
  25. package/dist/es2019/rules/no-imported-style-values/index.js +1 -1
  26. package/dist/es2019/rules/no-unsafe-values/index.js +1 -1
  27. package/dist/esm/rules/no-array-arguments/index.js +3 -3
  28. package/dist/esm/rules/no-dynamic-styles/index.js +2 -2
  29. package/dist/esm/rules/no-imported-style-values/index.js +2 -2
  30. package/dist/esm/rules/no-unsafe-values/index.js +2 -2
  31. package/package.json +8 -3
  32. package/src/rules/atlaskit-theme/README.md +74 -55
  33. package/src/rules/convert-props-syntax/README.md +29 -24
  34. package/src/rules/enforce-style-prop/README.md +32 -26
  35. package/src/rules/local-cx-xcss/README.md +27 -15
  36. package/src/rules/no-array-arguments/README.md +12 -9
  37. package/src/rules/no-array-arguments/index.tsx +2 -2
  38. package/src/rules/no-classname-prop/README.md +13 -5
  39. package/src/rules/no-container-queries/README.md +65 -16
  40. package/src/rules/no-dynamic-styles/README.md +16 -11
  41. package/src/rules/no-dynamic-styles/index.tsx +1 -1
  42. package/src/rules/no-exported-styles/README.md +25 -30
  43. package/src/rules/no-global-styles/README.md +4 -3
  44. package/src/rules/no-important-styles/README.md +5 -3
  45. package/src/rules/no-imported-style-values/README.md +30 -27
  46. package/src/rules/no-imported-style-values/index.tsx +1 -1
  47. package/src/rules/no-nested-selectors/README.md +51 -18
  48. package/src/rules/no-styled/README.md +17 -14
  49. package/src/rules/no-unsafe-selectors/README.md +184 -58
  50. package/src/rules/no-unsafe-values/README.md +150 -48
  51. package/src/rules/no-unsafe-values/index.tsx +1 -1
  52. package/src/rules/use-compiled/README.md +8 -8
@@ -1,12 +1,12 @@
1
- This rule prevents the usage of styles that are difficult/impossible to statically analyze.
1
+ Blocks styles that are difficult or impossible to statically analyze.
2
2
 
3
3
  ## Examples
4
4
 
5
- ### Incorrect
5
+ ### Function calls
6
6
 
7
- **Function calls**
7
+ #### Incorrect
8
8
 
9
- Function calls are not allowed as arguments or as values, unless they are specified in
9
+ Function calls are blocked as arguments or as values, unless they are specified in
10
10
  `allowedFunctionCalls` (or in the default list).
11
11
 
12
12
  ```tsx
@@ -31,48 +31,121 @@ const styles = css({
31
31
  });
32
32
  ```
33
33
 
34
- **Dynamic keys**
34
+ #### Correct
35
35
 
36
- Dynamic keys are not allowed, unless they are specified in `allowedDynamicKeys` (or in the default
36
+ Use inline literals for static values.
37
+
38
+ ```tsx
39
+ import { css } from '@compiled/react';
40
+
41
+ const styles = css({ width: 100 });
42
+ ```
43
+
44
+ Use the `style` prop for dynamic values.
45
+
46
+ ```tsx
47
+ const Component = ({ width }) => <div style={{ width }} />;
48
+ ```
49
+
50
+ Some functions such as `tokens()` are allowed.
51
+
52
+ ```tsx
53
+ import { css } from '@compiled/react';
54
+ import { token } from '@atlaskit/tokens';
55
+
56
+ const styles = css({ padding: token('space.100') });
57
+ ```
58
+
59
+ ### Dynamic keys
60
+
61
+ #### Incorrect
62
+
63
+ Dynamic keys are blocked, unless they are specified in `allowedDynamicKeys` (or in the default
37
64
  list).
38
65
 
39
66
  ```tsx
40
67
  import { css } from '@compiled/react';
41
- import { SELECTOR } from 'my-package';
68
+
69
+ const HOVER_SELECTOR = '&:hover';
70
+ const MARGIN = 'margin';
42
71
 
43
72
  const styles = css({
44
- [SELECTOR]: {
45
- color: 'red',
73
+ [HOVER_SELECTOR]: {
74
+ [MARGIN]: 0,
46
75
  },
47
- [`${SELECTOR} > p`]: {
76
+ [`${HOVER_SELECTOR} > p`]: {
48
77
  width: 100,
49
78
  },
50
79
  });
51
80
  ```
52
81
 
53
- **Variables**
82
+ #### Correct
54
83
 
55
- Variables are not allowed as values, unless they:
84
+ Use literal values for pseudo-states and property names.
56
85
 
57
- - Have a simple, static value
58
- - Are defined in the same file
86
+ Don't use nested selectors, apply styles directly instead.
59
87
 
60
88
  ```tsx
61
89
  import { css } from '@compiled/react';
62
- import { SELECTOR } from 'my-package';
63
90
 
64
- function myFunction() {
65
- return '5px';
66
- }
91
+ const styles = css({
92
+ '&:hover': {
93
+ margin: 0,
94
+ },
95
+ });
96
+
97
+ const paragraphStyles = css({
98
+ width: 100,
99
+ });
100
+ ```
101
+
102
+ ### Variables
103
+
104
+ #### Incorrect
105
+
106
+ Variables are only allowed as values if they:
107
+
108
+ - have a simple, static value
109
+ - are defined in the same file
110
+
111
+ ```tsx
112
+ import { css } from '@compiled/react';
113
+ import { HEIGHT } from '../shared';
114
+
115
+ const styles = css({
116
+ height: HEIGHT,
117
+ });
118
+ ```
119
+
120
+ #### Correct
121
+
122
+ Use inlined values.
123
+
124
+ ```tsx
125
+ import { css } from '@compiled/react';
126
+
127
+ const styles = css({
128
+ height: '32px',
129
+ });
130
+ ```
131
+
132
+ Alternatively, define variables in the same file.
133
+
134
+ ```tsx
135
+ import { css } from '@compiled/react';
136
+
137
+ const HEIGHT = '32px';
67
138
 
68
139
  const styles = css({
69
- height: myFunction,
140
+ height: HEIGHT,
70
141
  });
71
142
  ```
72
143
 
73
- **Object access**
144
+ ### Object access
74
145
 
75
- Accessing object members is not allowed in values.
146
+ #### Incorrect
147
+
148
+ Don't access object members in values.
76
149
 
77
150
  ```tsx
78
151
  import { css } from '@compiled/react';
@@ -87,59 +160,89 @@ const styles = css({
87
160
  });
88
161
  ```
89
162
 
90
- **Spread elements**
163
+ #### Correct
91
164
 
92
- Spread elements are not allowed.
165
+ Use inlined values.
93
166
 
94
167
  ```tsx
95
168
  import { css } from '@compiled/react';
169
+ import { token } from '@atlaskit/tokens';
170
+
171
+ const styles = css({
172
+ color: token('color.text'),
173
+ });
174
+ ```
175
+
176
+ ### Spread elements
177
+
178
+ #### Incorrect
96
179
 
97
- const buttonStyles = {
98
- color: 'blue',
180
+ Don't use the spread operator in styles.
181
+
182
+ ```tsx
183
+ import { css } from '@compiled/react';
184
+ import { token } from '@atlaskit/tokens';
185
+
186
+ const subtleTextStyles = {
187
+ color: token('color.text.subtle'),
99
188
  };
100
189
 
101
190
  const styles = css({
102
- ...buttonStyles,
191
+ ...subtleTextStyles,
192
+ margin: 0,
103
193
  });
104
194
  ```
105
195
 
106
- **Array values**
196
+ #### Correct
107
197
 
108
- Array values are not allowed. This syntax is not supported by most styling libraries.
198
+ Use the `css` prop to compose styles.
109
199
 
110
200
  ```tsx
111
201
  import { css } from '@compiled/react';
202
+ import { token } from '@atlaskit/tokens';
203
+
204
+ const subtleTextStyles = {
205
+ color: token('color.text.subtle'),
206
+ };
112
207
 
113
208
  const styles = css({
114
- '::before': [{ fontWeight: 'bold' }, { color: 'red' }],
209
+ margin: 0,
115
210
  });
211
+
212
+ const Component = () => <div css={[subtleTextStyles, styles]} />;
116
213
  ```
117
214
 
118
- ### Correct
215
+ ### Array values
119
216
 
120
- Things to note about the following example:
217
+ #### Incorrect
121
218
 
122
- - The `warningStyles` are conditionally applied using the `css` prop
123
- - The dynamic `width` is applied using the `style` prop
124
- - The `token()` calls are allowed because they are statically analyzable (and in the default
125
- allow-list)
219
+ Don't use array values. This syntax is not supported by Compiled, or most other CSS-in-JS libraries.
126
220
 
127
221
  ```tsx
128
222
  import { css } from '@compiled/react';
129
223
  import { token } from '@atlaskit/tokens';
130
224
 
131
- const baseStyles = css({
132
- height: 100,
133
- });
225
+ const boldMixin = { fontWeight: token('font.weight.bold') };
134
226
 
135
- const warningStyles = css({
136
- color: token('color.text.warning'),
137
- backgroundColor: token('color.background.warning'),
227
+ const styles = css({
228
+ '&::before': [boldMixin, { color: token('color.text.danger') }],
138
229
  });
230
+ ```
139
231
 
140
- const Component = ({ isWarning, width }: { isWarning: boolean; width: number }) => {
141
- return <div style={{ width }} css={[baseStyles, isWarning && warningStyles]} />;
142
- };
232
+ #### Correct
233
+
234
+ Use a single object with inlined styles.
235
+
236
+ ```tsx
237
+ import { css } from '@compiled/react';
238
+ import { token } from '@atlaskit/tokens';
239
+
240
+ const styles = css({
241
+ '&::before': {
242
+ fontWeight: token('font.weight.bold'),
243
+ color: token('color.text.danger'),
244
+ },
245
+ });
143
246
  ```
144
247
 
145
248
  ## Options
@@ -198,9 +301,9 @@ Default imports are not currently supported.
198
301
  // ...
199
302
  ```
200
303
 
201
- ### `importSources : string[]`
304
+ ### `importSources: string[]`
202
305
 
203
- By default, this rule will check `css` usages from:
306
+ By default, this rule will check styles using:
204
307
 
205
308
  - `@atlaskit/css`
206
309
  - `@atlaskit/primitives`
@@ -210,5 +313,4 @@ By default, this rule will check `css` usages from:
210
313
  - `@emotion/styled`
211
314
  - `styled-components`
212
315
 
213
- To change this list of libraries, you can define a custom set of `importSources`, which accepts an
214
- array of package names (strings). This will override the built-in allow-list.
316
+ Override this list with the `importSources` option, which accepts an array of package names.
@@ -62,7 +62,7 @@ export const rule = createLintRule({
62
62
 
63
63
  return {
64
64
  CallExpression(node) {
65
- const { references } = context.sourceCode.getScope(node);
65
+ const { references } = context.getScope();
66
66
 
67
67
  if (
68
68
  !isCss(node.callee, references, importSources) &&
@@ -1,21 +1,21 @@
1
- Ensures usage of `@compiled/react` over other CSS-in-JS libraries like Emotion or styled-components.
1
+ Blocks CSS-in-JS libraries other than `@compiled/react`, including Emotion and styled-components.
2
2
 
3
3
  **WARNING** It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on
4
4
  the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the
5
- auto-fixer has been disabled by default, but it may be useful to enable to empower a migration.
5
+ autofixer has been disabled by default, but it may be useful to enable to empower a migration.
6
6
 
7
7
  ## Examples
8
8
 
9
9
  ### Incorrect
10
10
 
11
- ```js
11
+ ```tsx
12
12
  /** @jsx jsx */
13
13
  import { css } from '@emotion/core';
14
14
  import { jsx } from '@emotion/react';
15
15
  import styled from '@emotion/styled';
16
16
  ```
17
17
 
18
- ```js
18
+ ```tsx
19
19
  import styled, { css } from 'styled-components';
20
20
  ```
21
21
 
@@ -24,7 +24,7 @@ import styled, { css } from 'styled-components';
24
24
  We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with
25
25
  `@compiled/react` when working with custom or native code.
26
26
 
27
- ```js
27
+ ```tsx
28
28
  /** @jsx jsx */
29
29
  import { jsx, css, styled } from '@compiled/react';
30
30
 
@@ -32,7 +32,7 @@ const styles = css({ color: 'var(--ds-color-text)' });
32
32
  export default () => <div css={styles}>…</div>;
33
33
  ```
34
34
 
35
- ```js
35
+ ```tsx
36
36
  import { xcss, Box } from '@atlaskit/primitives';
37
37
 
38
38
  const styles = xcss({ color: 'color.text' });
@@ -43,10 +43,10 @@ export default () => <Box xcss={styles}>…</Box>;
43
43
 
44
44
  ### `canAutoFix: boolean`
45
45
 
46
- Determines whether or not the auto-fixer is enabled.
46
+ Determines whether or not the autofixer is enabled.
47
47
 
48
48
  Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the
49
49
  same component.
50
50
 
51
- Even when enabled, the auto-fixer will only convert usages that are deemed safe. Currently this is
51
+ Even when enabled, the autofixer will only convert usages that are deemed safe. Currently this is
52
52
  limited to purely static styles where all keys and values are simple literals.