@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.0

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 (95) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/constellation/index/migration-guide.mdx +309 -0
  3. package/constellation/index/overview.mdx +4 -0
  4. package/constellation/index/props.mdx +9 -5
  5. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
  6. package/index.js +9 -9
  7. package/package.json +3 -3
  8. package/scripts/codegen.tsx +223 -284
  9. package/src/rules/__tests__/utils/_tester.tsx +24 -24
  10. package/src/rules/atlaskit-theme/README.md +21 -19
  11. package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
  12. package/src/rules/atlaskit-theme/index.ts +107 -115
  13. package/src/rules/convert-props-syntax/README.md +32 -22
  14. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
  15. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
  16. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
  17. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
  18. package/src/rules/convert-props-syntax/index.tsx +356 -386
  19. package/src/rules/enforce-style-prop/README.md +21 -18
  20. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
  21. package/src/rules/enforce-style-prop/index.tsx +144 -160
  22. package/src/rules/external-rules.tsx +163 -164
  23. package/src/rules/local-cx-xcss/README.md +10 -6
  24. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
  25. package/src/rules/local-cx-xcss/index.tsx +46 -56
  26. package/src/rules/no-array-arguments/README.md +2 -1
  27. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
  28. package/src/rules/no-array-arguments/index.tsx +68 -69
  29. package/src/rules/no-classname-prop/README.md +7 -4
  30. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
  31. package/src/rules/no-classname-prop/index.tsx +25 -25
  32. package/src/rules/no-container-queries/README.md +11 -9
  33. package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
  34. package/src/rules/no-container-queries/index.tsx +75 -81
  35. package/src/rules/no-dynamic-styles/README.md +16 -19
  36. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
  37. package/src/rules/no-dynamic-styles/index.tsx +45 -48
  38. package/src/rules/no-exported-styles/README.md +17 -12
  39. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
  40. package/src/rules/no-exported-styles/index.tsx +36 -36
  41. package/src/rules/no-global-styles/README.md +15 -14
  42. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
  43. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
  44. package/src/rules/no-global-styles/index.tsx +59 -62
  45. package/src/rules/no-important-styles/README.md +5 -3
  46. package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
  47. package/src/rules/no-important-styles/index.tsx +49 -49
  48. package/src/rules/no-imported-style-values/README.md +23 -15
  49. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
  50. package/src/rules/no-imported-style-values/index.tsx +116 -120
  51. package/src/rules/no-nested-selectors/README.md +15 -13
  52. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +128 -128
  53. package/src/rules/no-styled/README.md +14 -9
  54. package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
  55. package/src/rules/no-styled/index.tsx +34 -41
  56. package/src/rules/no-unsafe-selectors/README.md +103 -93
  57. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
  58. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
  59. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
  60. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
  61. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
  62. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
  63. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
  64. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
  65. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
  66. package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
  67. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
  68. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
  69. package/src/rules/no-unsafe-values/README.md +34 -40
  70. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
  71. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
  72. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
  73. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
  74. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
  75. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
  76. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
  77. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
  78. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
  79. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
  80. package/src/rules/no-unsafe-values/index.tsx +76 -78
  81. package/src/rules/no-unsafe-values/messages.tsx +12 -12
  82. package/src/rules/no-unsafe-values/utils.tsx +370 -382
  83. package/src/rules/use-compiled/README.md +11 -8
  84. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
  85. package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
  86. package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
  87. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
  88. package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
  89. package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
  90. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
  91. package/src/rules/use-compiled/index.tsx +203 -226
  92. package/src/rules/use-compiled/is-safe.tsx +113 -117
  93. package/src/rules/use-compiled/utils.tsx +14 -18
  94. package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
  95. package/src/rules/utils/create-rule.tsx +3 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#109850](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/109850)
8
+ [`9a18d4ad09473`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9a18d4ad09473) -
9
+ Added migration guide to styling standard documentation.
10
+
3
11
  ## 0.15.2
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,309 @@
1
+ ---
2
+ order: 3
3
+ ---
4
+
5
+ import SectionMessage from '@atlaskit/section-message';
6
+ import Tabs, { Tab, TabList, TabPanel } from '@atlaskit/tabs';
7
+
8
+ ## Patterns
9
+
10
+ All styles should be written using [Compiled](https://compiledcssinjs.com/) or
11
+ [Primitives](/components/primitives) and conform to the following patterns.
12
+
13
+ ### Static styles
14
+
15
+ For styles that are not affected by props or state, use the `css()` or `xcss()` API.
16
+
17
+ #### Compiled
18
+
19
+ When using Compiled, write static styles with `css()` and apply them with the `css` prop.
20
+
21
+ ```tsx
22
+ import { css } from '@compiled/react';
23
+ import { token } from '@atlaskit/tokens';
24
+
25
+ const cardStyles = css({
26
+ backgroundColor: token('elevation.surface.raised'),
27
+ boxShadow: token('elevation.shadow.raised'),
28
+ padding: token('space.100'),
29
+ });
30
+
31
+ const Card = () => <div css={cardStyles} />;
32
+ ```
33
+
34
+ #### Primitives
35
+
36
+ When using Primitives, write static styles with `xcss()` and apply them with the `xcss` prop.
37
+
38
+ ```tsx
39
+ import { Box, xcss } from '@atlaskit/primitives';
40
+
41
+ const cardStyles = xcss({
42
+ backgroundColor: 'elevation.surface.raised',
43
+ boxShadow: 'elevation.shadow.raised',
44
+ padding: 'space.100',
45
+ });
46
+
47
+ const Card = () => <Box xcss={cardStyles} />;
48
+ ```
49
+
50
+ ### Toggled styles
51
+
52
+ For styles that are toggled on and off, write them as [static styles](#static-styles) and then
53
+ conditionally apply them.
54
+
55
+ #### Compiled
56
+
57
+ When using Compiled, conditionally apply styles with the `css` prop.
58
+
59
+ ```tsx
60
+ import { css } from '@compiled/react';
61
+ import { token } from '@atlaskit/tokens';
62
+
63
+ const baseStyles = css({
64
+ backgroundColor: token('color.background.neutral'),
65
+ border: `1px solid ${token('color.border')}`,
66
+ });
67
+
68
+ const selectedStyles = css({
69
+ backgroundColor: token('color.background.selected'),
70
+ borderColor: token('color.border.selected'),
71
+ });
72
+
73
+ const Selectable = ({ isSelected = false }: { isSelected?: boolean }) => (
74
+ // The `selectedStyles` are conditionally applied
75
+ <div css={[baseStyles, isSelected && selectedStyles]} />
76
+ );
77
+ ```
78
+
79
+ #### Primitives
80
+
81
+ When using Primitives, conditionally apply styles with the `xcss` prop.
82
+
83
+ ```tsx
84
+ import { Box, xcss } from '@atlaskit/primitives';
85
+
86
+ const baseStyles = xcss({
87
+ backgroundColor: 'color.background.neutral',
88
+ borderWidth: '1px',
89
+ borderStyle: 'solid',
90
+ borderColor: 'color.border',
91
+ });
92
+
93
+ const selectedStyles = xcss({
94
+ backgroundColor: 'color.background.selected',
95
+ borderColor: 'color.border.selected',
96
+ });
97
+
98
+ const Selectable = ({ isSelected = false }: { isSelected?: boolean }) => (
99
+ // The `selectedStyles` are conditionally applied
100
+ <Box xcss={[baseStyles, isSelected && selectedStyles]} />
101
+ );
102
+ ```
103
+
104
+ ### Variant styles
105
+
106
+ For styles that compose a set of known variants, use `cssMap` or an object of `xcss()` styles and
107
+ then dynamically access them.
108
+
109
+ #### Compiled
110
+
111
+ When using Compiled, write variants with `cssMap` and apply them with the `css` prop.
112
+
113
+ ```tsx
114
+ import { css, cssMap } from '@compiled/react';
115
+ import { token } from '@atlaskit/tokens';
116
+
117
+ type Status = 'success' | 'warning' | 'danger';
118
+
119
+ const baseStyles = css({
120
+ font: token('font.body.large'),
121
+ padding: token('space.100'),
122
+ });
123
+
124
+ const statusStyles = cssMap({
125
+ success: {
126
+ color: token('color.text.success'),
127
+ backgroundColor: token('color.background.success'),
128
+ },
129
+ warning: {
130
+ color: token('color.text.warning'),
131
+ backgroundColor: token('color.background.warning'),
132
+ },
133
+ danger: {
134
+ color: token('color.text.danger'),
135
+ backgroundColor: token('color.background.danger'),
136
+ },
137
+ });
138
+
139
+ const StatusMessage = ({ message, status }: { message: string; status: Status }) => (
140
+ // The `statusStyles` are dynamically accessed
141
+ <div css={[baseStyles, statusStyles[status]]} />
142
+ );
143
+ ```
144
+
145
+ #### Primitives
146
+
147
+ When using Primitives, write variants using an object with `xcss()` values and apply them with the
148
+ `xcss` prop.
149
+
150
+ ```tsx
151
+ import { Box, xcss } from '@atlaskit/primitives';
152
+
153
+ type Status = 'success' | 'warning' | 'danger';
154
+
155
+ const baseStyles = xcss({
156
+ font: 'font.body.large',
157
+ padding: 'space.100',
158
+ });
159
+
160
+ const statusStyles = {
161
+ success: xcss({
162
+ color: 'color.text.success',
163
+ backgroundColor: 'color.background.success',
164
+ }),
165
+ warning: xcss({
166
+ color: 'color.text.warning',
167
+ backgroundColor: 'color.background.warning',
168
+ }),
169
+ danger: xcss({
170
+ color: 'color.text.danger',
171
+ backgroundColor: 'color.background.danger',
172
+ }),
173
+ };
174
+
175
+ const StatusMessage = ({ message, status }: { message: string; status: Status }) => (
176
+ // The `statusStyles` are dynamically accessed
177
+ <Box xcss={[baseStyles, statusStyles[status]]} />
178
+ );
179
+ ```
180
+
181
+ ### Dynamic styles
182
+
183
+ <SectionMessage appearance="warning" title="Use with caution">
184
+ Only a tiny percentage (~1%) of styles need to be written this way. If you are using it
185
+ frequently, you are likely doing something wrong!
186
+ </SectionMessage>
187
+
188
+ For styles that cannot be expressed statically, use the `style` prop.
189
+
190
+ This might be needed when:
191
+
192
+ - Styles are derived from user input
193
+ - Integrating with a 3rd party library that provides a `style` object
194
+
195
+ #### Compiled
196
+
197
+ ```tsx
198
+ import { css } from '@compiled/react';
199
+ import { token } from '@atlaskit/tokens';
200
+
201
+ const baseStyles = css({
202
+ height: '100%',
203
+ minWidth: '200px',
204
+ backgroundColor: token('color.background.neutral'),
205
+ });
206
+
207
+ const Resizable = ({ width }: { width: string }) => <div css={baseStyles} style={{ width }} />;
208
+ ```
209
+
210
+ #### Primitives
211
+
212
+ ```tsx
213
+ import { Box, xcss } from '@atlaskit/primitives';
214
+
215
+ const baseStyles = xcss({
216
+ height: '100%',
217
+ minWidth: '200px',
218
+ backgroundColor: 'color.background.neutral',
219
+ });
220
+
221
+ const Resizable = ({ width }: { width: string }) => <Box css={baseStyles} style={{ width }} />;
222
+ ```
223
+
224
+ ## More examples
225
+
226
+ ### Migrating from `styled`
227
+
228
+ #### Before
229
+
230
+ ```tsx
231
+ import { styled } from '@compiled/react';
232
+
233
+ type Status = 'success' | 'warning' | 'danger';
234
+
235
+ type Props = {
236
+ width: string;
237
+ status: Status;
238
+ isSelected: boolean;
239
+ };
240
+
241
+ const textColors: Record<Status, string> = {
242
+ success: token('color.text.success'),
243
+ warning: token('color.text.warning'),
244
+ danger: token('color.text.danger'),
245
+ };
246
+
247
+ const Component = styled.div<Props>(
248
+ {
249
+ padding: token('space.100'),
250
+ width: (props) => props.width,
251
+ },
252
+ ({ status }: { status: Status }) => ({
253
+ color: textColors[status],
254
+ }),
255
+ ({ isSelected }) => (isSelected ? { border: `1px solid ${token('color.border.selected')}` } : {}),
256
+ );
257
+ ```
258
+
259
+ #### After
260
+
261
+ We apply a combination of the patterns above:
262
+
263
+ - The padding is a [static style](#static-styles) so uses `css()` that is always applied.
264
+ - The selected border is a [toggled style](#toggled-styles) so uses `css()` that is conditionally
265
+ applied.
266
+ - The status color is a [variant style](#variant-styles) so is written using `cssMap()` that is
267
+ dynamically accessed.
268
+ - The width is a [completely dynamic style](#dynamic-styles) so uses the `style` prop.
269
+
270
+ ```tsx
271
+ import type { ReactNode } from 'react';
272
+ import { css, cssMap } from '@compiled/react';
273
+
274
+ type Status = 'success' | 'warning' | 'danger';
275
+
276
+ type Props = {
277
+ width: string;
278
+ status: Status;
279
+ isSelected: boolean;
280
+ // Props that were implicitly added now need to be made explicit
281
+ children: ReactNode;
282
+ };
283
+
284
+ const baseStyles = css({
285
+ padding: token('space.100'),
286
+ });
287
+
288
+ const selectedStyles = css({
289
+ border: `1px solid ${token('color.border.selected')}`,
290
+ });
291
+
292
+ const statusStyles = cssMap({
293
+ success: {
294
+ color: token('color.text.success'),
295
+ },
296
+ warning: {
297
+ color: token('color.text.warning'),
298
+ },
299
+ danger: {
300
+ color: token('color.text.danger'),
301
+ },
302
+ });
303
+
304
+ const Component = ({ width, status, isSelected, children }: Props) => (
305
+ <div css={[baseStyles, isSelected && selectedStyles, statusStyles[status]]} style={{ width }}>
306
+ {children}
307
+ </div>
308
+ );
309
+ ```
@@ -1,3 +1,7 @@
1
+ ---
2
+ order: 1
3
+ ---
4
+
1
5
  The UI Styling Standard is a set of principles to guide styling UI code across Atlassian's frontend
2
6
  codebases and ecosystem.
3
7
 
@@ -1,5 +1,9 @@
1
- You must use the recommended config to follow the styling standards at Atlassian,
2
- which will ensure compatability and performance with the design system.
1
+ ---
2
+ order: 2
3
+ ---
4
+
5
+ You must use the recommended config to follow the styling standards at Atlassian, which will ensure
6
+ compatability and performance with the design system.
3
7
 
4
8
  ```diff
5
9
  module.exports = {
@@ -9,9 +13,9 @@ module.exports = {
9
13
  };
10
14
  ```
11
15
 
12
- We don't recommended maintaining your own configuration.
13
- If you do not use our config you will need to specify individual rules and configuration.
14
- Add the plugin to your `.eslintrc.js` file and enable individual rules as you're ready to adopt.
16
+ We don't recommended maintaining your own configuration. If you do not use our config you will need
17
+ to specify individual rules and configuration. Add the plugin to your `.eslintrc.js` file and enable
18
+ individual rules as you're ready to adopt.
15
19
 
16
20
  ```diff
17
21
  module.exports = {
@@ -4,10 +4,7 @@ import type { CSSPseudos } from '@compiled/react';
4
4
  * https://stackoverflow.com/a/71236280
5
5
  */
6
6
  type Validate<T extends true> = T;
7
- type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [
8
- infer Head,
9
- ...infer Tail
10
- ] ? Head extends Seen ? {
7
+ type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [infer Head, ...infer Tail] ? Head extends Seen ? {
11
8
  ERROR: ['The following key appears more than once in the tuple:', Head];
12
9
  } : HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen> : [Union] extends [never] ? true : {
13
10
  ERROR: ['Some keys are missing from the tuple:', Union];
package/index.js CHANGED
@@ -6,19 +6,19 @@ const path = require('path');
6
6
  const paths = require('tsconfig-paths');
7
7
 
8
8
  if (!require.extensions['.ts']) {
9
- // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
10
- require('ts-node').register({
11
- project: path.join(__dirname, 'tsconfig.json'),
12
- });
9
+ // ts-node can only handle being registered once, see https://github.com/TypeStrong/ts-node/issues/409
10
+ require('ts-node').register({
11
+ project: path.join(__dirname, 'tsconfig.json'),
12
+ });
13
13
  }
14
14
 
15
15
  try {
16
- // We programatically register tsconfig paths here so it picks up the tsconfig here
17
- // instead of in root CWD.
18
- paths.register(paths.loadConfig(__dirname));
16
+ // We programatically register tsconfig paths here so it picks up the tsconfig here
17
+ // instead of in root CWD.
18
+ paths.register(paths.loadConfig(__dirname));
19
19
  } catch (e) {
20
- // eslint-disable-next-line no-console
21
- console.log(e);
20
+ // eslint-disable-next-line no-console
21
+ console.log(e);
22
22
  }
23
23
 
24
24
  module.exports = require('./src/index');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.15.2",
3
+ "version": "0.16.0",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",
@@ -39,7 +39,7 @@
39
39
  ".": "./src/index.tsx"
40
40
  },
41
41
  "dependencies": {
42
- "@atlaskit/eslint-utils": "^1.5.0",
42
+ "@atlaskit/eslint-utils": "^1.6.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "@typescript-eslint/utils": "^5.48.1",
45
45
  "ajv": "^6.12.6",
@@ -54,7 +54,7 @@
54
54
  "devDependencies": {
55
55
  "@af/formatting": "*",
56
56
  "@atlaskit/ds-lib": "^2.3.0",
57
- "@atlaskit/eslint-plugin-design-system": "^10.4.0",
57
+ "@atlaskit/eslint-plugin-design-system": "^10.6.0",
58
58
  "@atlassian/codegen": "*",
59
59
  "@compiled/eslint-plugin": "^0.13.6",
60
60
  "@types/eslint": "^8.56.6",