@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.
Files changed (105) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/constellation/consistent-css-prop-usage/usage.mdx +3 -1
  3. package/constellation/index/migration-guide.mdx +309 -0
  4. package/constellation/index/overview.mdx +4 -0
  5. package/constellation/index/props.mdx +9 -5
  6. package/constellation/no-css-tagged-template-expression/usage.mdx +5 -2
  7. package/constellation/no-empty-styled-expression/usage.mdx +5 -2
  8. package/constellation/no-exported-css/usage.mdx +5 -2
  9. package/constellation/no-exported-keyframes/usage.mdx +5 -2
  10. package/constellation/no-invalid-css-map/usage.mdx +5 -2
  11. package/constellation/no-js-xcss/usage.mdx +3 -1
  12. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -2
  13. package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -2
  14. package/constellation/no-suppress-xcss/usage.mdx +6 -3
  15. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
  16. package/index.js +9 -9
  17. package/package.json +3 -3
  18. package/scripts/codegen.tsx +223 -284
  19. package/src/rules/__tests__/utils/_tester.tsx +24 -24
  20. package/src/rules/atlaskit-theme/README.md +21 -19
  21. package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
  22. package/src/rules/atlaskit-theme/index.ts +107 -115
  23. package/src/rules/convert-props-syntax/README.md +32 -22
  24. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
  25. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
  26. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
  27. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
  28. package/src/rules/convert-props-syntax/index.tsx +356 -386
  29. package/src/rules/enforce-style-prop/README.md +21 -18
  30. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
  31. package/src/rules/enforce-style-prop/index.tsx +144 -160
  32. package/src/rules/external-rules.tsx +163 -164
  33. package/src/rules/local-cx-xcss/README.md +10 -6
  34. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
  35. package/src/rules/local-cx-xcss/index.tsx +46 -56
  36. package/src/rules/no-array-arguments/README.md +2 -1
  37. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
  38. package/src/rules/no-array-arguments/index.tsx +68 -69
  39. package/src/rules/no-classname-prop/README.md +7 -4
  40. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
  41. package/src/rules/no-classname-prop/index.tsx +25 -25
  42. package/src/rules/no-container-queries/README.md +11 -9
  43. package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
  44. package/src/rules/no-container-queries/index.tsx +75 -81
  45. package/src/rules/no-dynamic-styles/README.md +16 -19
  46. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
  47. package/src/rules/no-dynamic-styles/index.tsx +45 -48
  48. package/src/rules/no-exported-styles/README.md +17 -12
  49. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
  50. package/src/rules/no-exported-styles/index.tsx +36 -36
  51. package/src/rules/no-global-styles/README.md +15 -14
  52. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
  53. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
  54. package/src/rules/no-global-styles/index.tsx +59 -62
  55. package/src/rules/no-important-styles/README.md +5 -3
  56. package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
  57. package/src/rules/no-important-styles/index.tsx +49 -49
  58. package/src/rules/no-imported-style-values/README.md +23 -15
  59. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
  60. package/src/rules/no-imported-style-values/index.tsx +116 -120
  61. package/src/rules/no-nested-selectors/README.md +15 -13
  62. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +141 -128
  63. package/src/rules/no-styled/README.md +14 -9
  64. package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
  65. package/src/rules/no-styled/index.tsx +34 -41
  66. package/src/rules/no-unsafe-selectors/README.md +103 -93
  67. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
  68. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
  69. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
  70. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
  71. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
  72. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
  73. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
  74. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
  75. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +133 -114
  76. package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
  77. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
  78. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
  79. package/src/rules/no-unsafe-values/README.md +34 -40
  80. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
  81. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
  82. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
  83. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
  84. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
  85. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
  86. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
  87. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
  88. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
  89. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
  90. package/src/rules/no-unsafe-values/index.tsx +76 -78
  91. package/src/rules/no-unsafe-values/messages.tsx +12 -12
  92. package/src/rules/no-unsafe-values/utils.tsx +370 -382
  93. package/src/rules/use-compiled/README.md +11 -8
  94. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
  95. package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
  96. package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
  97. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
  98. package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
  99. package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
  100. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
  101. package/src/rules/use-compiled/index.tsx +203 -226
  102. package/src/rules/use-compiled/is-safe.tsx +113 -117
  103. package/src/rules/use-compiled/utils.tsx +14 -18
  104. package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
  105. 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 time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any other statically analysable values should be passed to the `style` attribute. Instead, static CSS values should be passed into the `css` prop in JSX components.
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
- return (
12
- <div
13
- style={{
14
- margin: 0,
15
- color: 'red',
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
- return (
27
- <div
28
- style={{
29
- width: props.width,
30
- '--my-nested-width': props.width,
31
- }}
32
- css={css({ margin: 0, color: 'red' })}
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
- valid: [
6
- {
7
- name: 'No style attribute used',
8
- code: `
5
+ valid: [
6
+ {
7
+ name: 'No style attribute used',
8
+ code: `
9
9
  <div css={styles} />
10
10
  `,
11
- },
12
- {
13
- name: 'Values from props are acceptable',
14
- code: `
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
- name: 'Values from deconstructed props are acceptable',
28
- code: `
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
- name: 'Multiple values from deconstructed props are acceptable',
36
- code: `
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
- name: 'Skips linting @media query as it is not supported by the style prop anyways',
44
- code: `
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
- name: 'Skips linting selector as it is not supported by the style prop anyways',
56
- code: `
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
- name: 'Static styles are outside of style attribute',
68
- code: `
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
- name: 'Props destructured in function via object pattern',
83
- code: `
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
- name: 'Props destructured in function via member expression',
92
- code: `
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
- name: 'Ignore state variables',
101
- code: `
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
- name: 'Ignore variables initialised by call expression',
110
- code: `
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
- name: 'Property from object initialisation is ok',
124
- code: `
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
- name: 'Let variables are ok',
137
- code: `
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
- name: 'Ignore function calls',
150
- code: `
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
- invalid: [
168
- {
169
- name: 'Basic test for static css values',
170
- code: `
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
- errors: [
181
- { messageId: 'enforce-style-prop' },
182
- { messageId: 'enforce-style-prop' },
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
- errors: [{ messageId: 'enforce-style-prop' }],
198
- },
199
- {
200
- name: 'No spread operator within style',
201
- code: `
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
- errors: [
214
- { messageId: 'enforce-style-prop' },
215
- { messageId: 'enforce-style-prop' },
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
- errors: [{ messageId: 'enforce-style-prop' }],
227
- },
228
- {
229
- name: 'No rest prop',
230
- code: `
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
- errors: [{ messageId: 'enforce-style-prop' }],
236
- },
237
- {
238
- name: 'No token calls',
239
- code: `
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
- errors: [{ messageId: 'enforce-style-prop' }],
247
- },
248
- ],
240
+ errors: [{ messageId: 'enforce-style-prop' }],
241
+ },
242
+ ],
249
243
  });