@atlaskit/eslint-plugin-ui-styling-standard 0.18.0 → 0.18.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 (137) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +1 -1
  3. package/afm-cc/tsconfig.json +0 -28
  4. package/afm-jira/tsconfig.json +0 -27
  5. package/build/tsconfig.json +0 -18
  6. package/constellation/atlaskit-theme/usage.mdx +0 -132
  7. package/constellation/consistent-css-prop-usage/usage.mdx +0 -7
  8. package/constellation/convert-props-syntax/usage.mdx +0 -130
  9. package/constellation/enforce-style-prop/usage.mdx +0 -47
  10. package/constellation/index/migration-guide.mdx +0 -309
  11. package/constellation/index/overview.mdx +0 -250
  12. package/constellation/index/props.mdx +0 -30
  13. package/constellation/local-cx-xcss/usage.mdx +0 -53
  14. package/constellation/no-array-arguments/usage.mdx +0 -49
  15. package/constellation/no-classname-prop/usage.mdx +0 -49
  16. package/constellation/no-container-queries/usage.mdx +0 -101
  17. package/constellation/no-css-tagged-template-expression/usage.mdx +0 -8
  18. package/constellation/no-dynamic-styles/usage.mdx +0 -130
  19. package/constellation/no-empty-styled-expression/usage.mdx +0 -8
  20. package/constellation/no-exported-css/usage.mdx +0 -8
  21. package/constellation/no-exported-keyframes/usage.mdx +0 -8
  22. package/constellation/no-exported-styles/usage.mdx +0 -87
  23. package/constellation/no-global-styles/usage.mdx +0 -60
  24. package/constellation/no-important-styles/usage.mdx +0 -33
  25. package/constellation/no-imported-style-values/usage.mdx +0 -157
  26. package/constellation/no-invalid-css-map/usage.mdx +0 -8
  27. package/constellation/no-js-xcss/usage.mdx +0 -7
  28. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -8
  29. package/constellation/no-nested-selectors/usage.mdx +0 -95
  30. package/constellation/no-styled/usage.mdx +0 -92
  31. package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -8
  32. package/constellation/no-suppress-xcss/usage.mdx +0 -28
  33. package/constellation/no-unsafe-selectors/usage.mdx +0 -370
  34. package/constellation/no-unsafe-values/usage.mdx +0 -318
  35. package/constellation/use-compiled/usage.mdx +0 -54
  36. package/index.js +0 -24
  37. package/scripts/codegen.tsx +0 -373
  38. package/src/index.codegen.tsx +0 -14
  39. package/src/index.tsx +0 -1
  40. package/src/presets/all.codegen.tsx +0 -79
  41. package/src/presets/recommended.codegen.tsx +0 -79
  42. package/src/rules/TEMPLATE.md +0 -29
  43. package/src/rules/__tests__/utils/_tester.tsx +0 -40
  44. package/src/rules/atlaskit-theme/README.md +0 -130
  45. package/src/rules/atlaskit-theme/__tests__/test.ts +0 -133
  46. package/src/rules/atlaskit-theme/index.ts +0 -134
  47. package/src/rules/convert-props-syntax/README.md +0 -128
  48. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +0 -76
  49. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +0 -584
  50. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +0 -140
  51. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +0 -69
  52. package/src/rules/convert-props-syntax/index.tsx +0 -414
  53. package/src/rules/enforce-style-prop/README.md +0 -45
  54. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +0 -243
  55. package/src/rules/enforce-style-prop/index.tsx +0 -172
  56. package/src/rules/external-rules.tsx +0 -177
  57. package/src/rules/index.codegen.tsx +0 -42
  58. package/src/rules/local-cx-xcss/README.md +0 -51
  59. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +0 -102
  60. package/src/rules/local-cx-xcss/index.tsx +0 -62
  61. package/src/rules/no-array-arguments/README.md +0 -47
  62. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +0 -107
  63. package/src/rules/no-array-arguments/index.tsx +0 -86
  64. package/src/rules/no-classname-prop/README.md +0 -47
  65. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +0 -39
  66. package/src/rules/no-classname-prop/index.tsx +0 -34
  67. package/src/rules/no-container-queries/README.md +0 -99
  68. package/src/rules/no-container-queries/__tests__/rule.test.tsx +0 -139
  69. package/src/rules/no-container-queries/index.tsx +0 -94
  70. package/src/rules/no-dynamic-styles/README.md +0 -128
  71. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +0 -135
  72. package/src/rules/no-dynamic-styles/index.tsx +0 -60
  73. package/src/rules/no-exported-styles/README.md +0 -85
  74. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +0 -216
  75. package/src/rules/no-exported-styles/index.tsx +0 -52
  76. package/src/rules/no-global-styles/README.md +0 -58
  77. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +0 -33
  78. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +0 -46
  79. package/src/rules/no-global-styles/index.tsx +0 -82
  80. package/src/rules/no-important-styles/README.md +0 -31
  81. package/src/rules/no-important-styles/__tests__/rule.test.tsx +0 -165
  82. package/src/rules/no-important-styles/index.tsx +0 -70
  83. package/src/rules/no-imported-style-values/README.md +0 -155
  84. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +0 -491
  85. package/src/rules/no-imported-style-values/index.tsx +0 -188
  86. package/src/rules/no-nested-selectors/README.md +0 -93
  87. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +0 -335
  88. package/src/rules/no-nested-selectors/index.tsx +0 -99
  89. package/src/rules/no-styled/README.md +0 -90
  90. package/src/rules/no-styled/__tests__/rule.test.tsx +0 -73
  91. package/src/rules/no-styled/index.tsx +0 -45
  92. package/src/rules/no-unsafe-selectors/README.md +0 -368
  93. package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +0 -368
  94. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +0 -57
  95. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +0 -73
  96. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +0 -40
  97. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +0 -101
  98. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +0 -131
  99. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +0 -132
  100. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +0 -25
  101. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +0 -35
  102. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +0 -257
  103. package/src/rules/no-unsafe-selectors/constants.tsx +0 -91
  104. package/src/rules/no-unsafe-selectors/index.tsx +0 -198
  105. package/src/rules/no-unsafe-selectors/lint-selector.tsx +0 -155
  106. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +0 -55
  107. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +0 -226
  108. package/src/rules/no-unsafe-values/README.md +0 -316
  109. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +0 -27
  110. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +0 -37
  111. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +0 -229
  112. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +0 -267
  113. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +0 -52
  114. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +0 -106
  115. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +0 -44
  116. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +0 -48
  117. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +0 -75
  118. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +0 -121
  119. package/src/rules/no-unsafe-values/index.tsx +0 -94
  120. package/src/rules/no-unsafe-values/messages.tsx +0 -86
  121. package/src/rules/no-unsafe-values/utils.tsx +0 -387
  122. package/src/rules/use-compiled/README.md +0 -52
  123. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +0 -73
  124. package/src/rules/use-compiled/__tests__/css.test.tsx +0 -126
  125. package/src/rules/use-compiled/__tests__/imports.test.tsx +0 -158
  126. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +0 -140
  127. package/src/rules/use-compiled/__tests__/pragma.test.tsx +0 -108
  128. package/src/rules/use-compiled/__tests__/styled.test.tsx +0 -114
  129. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +0 -15
  130. package/src/rules/use-compiled/index.tsx +0 -252
  131. package/src/rules/use-compiled/is-safe.tsx +0 -159
  132. package/src/rules/use-compiled/utils.tsx +0 -33
  133. package/src/rules/utils/create-rule-with-typed-config.tsx +0 -86
  134. package/src/rules/utils/create-rule.tsx +0 -13
  135. package/tsconfig.app.json +0 -47
  136. package/tsconfig.dev.json +0 -45
  137. package/tsconfig.json +0 -25
@@ -1,70 +0,0 @@
1
- import esquery from 'esquery';
2
-
3
- import type { Property } from 'estree';
4
-
5
- import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
6
- import { importSources } from '@atlaskit/eslint-utils/schema';
7
- import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
8
-
9
- export const rule = createLintRuleWithTypedConfig({
10
- meta: {
11
- name: 'no-important-styles',
12
- docs: {
13
- description: 'Disallows important style declarations',
14
- recommended: true,
15
- severity: 'error',
16
- },
17
- messages: {
18
- 'no-important-styles':
19
- 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.',
20
- },
21
- type: 'problem',
22
- schema: {
23
- type: 'object',
24
- properties: {
25
- importSources,
26
- },
27
- },
28
- },
29
- create(context, { importSources }) {
30
- return {
31
- CallExpression(node) {
32
- const { references } = context.getScope();
33
-
34
- if (!hasStyleObjectArguments(node.callee, references, importSources)) {
35
- return;
36
- }
37
-
38
- const matches = esquery(node, 'Property');
39
- for (const match of matches) {
40
- if (match.type !== 'Property') {
41
- return;
42
- }
43
-
44
- if (isImportant(match.value)) {
45
- context.report({
46
- node: match.value,
47
- messageId: 'no-important-styles',
48
- });
49
- }
50
- }
51
- },
52
- };
53
- },
54
- });
55
-
56
- export default rule;
57
-
58
- const importantRegex = /!\s*important\s*$/;
59
- function isImportant(node: Property['value']): boolean {
60
- if (node.type === 'Literal') {
61
- return typeof node.value === 'string' && importantRegex.test(node.value);
62
- }
63
-
64
- if (node.type === 'TemplateLiteral') {
65
- const joinedRaw = node.quasis.map((element) => element.value.raw).join('');
66
- return importantRegex.test(joinedRaw);
67
- }
68
-
69
- return false;
70
- }
@@ -1,155 +0,0 @@
1
- Blocks imported style values in `css`, `cssMap`, `styled`, `keyframes` and `xcss` calls.
2
-
3
- Use alongside `no-exported-styles` which blocks exporting styles.
4
-
5
- Compiled style declarations are null at runtime, so using imported styles will cause unexpected
6
- errors.
7
-
8
- Co-locate style definitions with their usage instead. This will also improve code readability and
9
- build performance.
10
-
11
- ## Examples
12
-
13
- ### Incorrect
14
-
15
- ```tsx
16
- import { css } from '@compiled/react';
17
- import { colors, getColor } from '../shared';
18
-
19
- const styles = css({
20
- color: getColor('red'),
21
- backgroundColor: colors['red'],
22
- });
23
- ```
24
-
25
- ```tsx
26
- import { css } from '@compiled/react';
27
- import { ff } from '@atlaskit/ff';
28
- import { buttonStyles, cssShared, HEIGHT, colorKey } from '../shared';
29
-
30
- const sharedObject = { padding: 0 };
31
-
32
- const styles = css({
33
- ...cssShared,
34
- ...sharedObject,
35
- height: `${HEIGHT}px`,
36
- width: ff('…') ? `${HEIGHT}px` : undefined,
37
- });
38
- ```
39
-
40
- Importing styles to use in style composition is not allowed.
41
-
42
- ```tsx
43
- import { css } from '@compiled/react';
44
- import { token } from '@atlaskit/tokens';
45
- import { buttonStyles } from '../shared';
46
-
47
- const styles = css({
48
- color: token('color.text'),
49
- });
50
-
51
- const Component = () => <div css={[styles, buttonStyles]} />;
52
- ```
53
-
54
- Importing styles to pass to the style prop is also not allowed.
55
-
56
- ```tsx
57
- import { importedWidth } from '../shared';
58
-
59
- const Component = () => <div style={{ width: importedWidth }} />;
60
- ```
61
-
62
- ### Correct
63
-
64
- Co-locate styles with components to improve code readability, linting, and build performance.
65
-
66
- ```tsx
67
- import { css } from '@compiled/react';
68
- import { token } from '@atlaskit/tokens';
69
-
70
- const styles = css({
71
- color: token('color.text'),
72
- padding: token('space.150'),
73
- });
74
-
75
- const Component = () => <div css={styles} />;
76
- ```
77
-
78
- ```tsx
79
- import { keyframes } from '@compiled/react';
80
-
81
- const animation = keyframes({});
82
- const styles = css({ animate: `${animation} 1s ease-in` });
83
-
84
- const Component = () => <div css={styles} />;
85
- ```
86
-
87
- ## Options
88
-
89
- ### `allowedDynamicKeys: [string, string][]`
90
-
91
- Use this to allow specified imports as dynamic keys, in addition to the built-in allow-list.
92
-
93
- Each value should be a two-element array. The first item is the entrypoint, and the second item is a
94
- named export.
95
-
96
- Default imports are not supported.
97
-
98
- ```tsx
99
- // .eslintrc.js
100
-
101
- // ...
102
- rules: {
103
- '@atlaskit/eslint-plugin-ui-styling-standard/no-unsafe-values': [
104
- 'error',
105
- {
106
- allowedDynamicKeys: [
107
- ['@atlaskit/primitives/responsive', 'media'],
108
- ]
109
- },
110
- ],
111
- // ...
112
- },
113
- // ...
114
- ```
115
-
116
- ### `allowedFunctionCalls: [string, string][]`
117
-
118
- Use this to allow specific functions to be called, in addition to the built-in allow-list.
119
-
120
- Each value should be a two-element array. The first item is the entrypoint, and the second item is a
121
- named export.
122
-
123
- Default imports are not currently supported.
124
-
125
- ```tsx
126
- // .eslintrc.js
127
-
128
- // ...
129
- rules: {
130
- '@atlaskit/eslint-plugin-ui-styling-standard/no-unsafe-values': [
131
- 'error',
132
- {
133
- allowedFunctionCalls: [
134
- ['@atlaskit/tokens', 'token'],
135
- ]
136
- },
137
- ],
138
- // ...
139
- },
140
- // ...
141
- ```
142
-
143
- ### `importSources: string[]`
144
-
145
- By default, this rule will check styles using:
146
-
147
- - `@atlaskit/css`
148
- - `@atlaskit/primitives`
149
- - `@compiled/react`
150
- - `@emotion/react`
151
- - `@emotion/core`
152
- - `@emotion/styled`
153
- - `styled-components`
154
-
155
- Override this list with the `importSources` option, which accepts an array of package names.
@@ -1,491 +0,0 @@
1
- import { typescriptEslintTester } from '../../__tests__/utils/_tester';
2
- import rule from '../index';
3
-
4
- typescriptEslintTester.run(
5
- 'no-imported-style-values',
6
- // @ts-expect-error
7
- rule,
8
- {
9
- valid: [
10
- {
11
- name: 'Basic valid test for css',
12
- code: `
13
- import { css } from '@compiled/react';
14
- const sharedObject = { padding: 0 };
15
- const styles = css({
16
- ...sharedObject,
17
- color: 'red',
18
- });
19
- `,
20
- },
21
- {
22
- name: 'Valid emotion css call',
23
- code: `
24
- import { css } from '@emotion/react';
25
- import { CURRENT_SURFACE_CSS_VAR, token } from '@atlaskit/tokens';
26
- const styles = css({
27
- backgroundColor: token('elevation.surface.overlay', N0),
28
- borderRadius: token('border.radius', '3px'),
29
- [CURRENT_SURFACE_CSS_VAR]: token('elevation.surface.overlay', N0),
30
- });
31
- `,
32
- },
33
- {
34
- name: 'Valid styled component',
35
- code: `
36
- import { styled } from '@compiled/react';
37
- import { token } from '@atlaskit/tokens';
38
- const Component = styled.div({
39
- borderRadius: token('border.radius', '3px')
40
- })
41
- `,
42
- },
43
- {
44
- name: 'Variables defined in same file',
45
- code: `
46
- import { css } from '@compiled/react';
47
- const color = 'red',
48
- const containerWidth = 0;
49
- const styles = css({
50
- color,
51
- width: containerWidth
52
- });
53
- `,
54
- },
55
- {
56
- name: 'Importing token function',
57
- code: `
58
- import { css } from '@compiled/react';
59
- import { token } from '@atlaskit/tokens';
60
- const styles = css({
61
- padding: token('space.150'),
62
- });
63
- `,
64
- },
65
- {
66
- name: 'Valid cssMap call',
67
- code: `
68
- import { cssMap } from '@compiled/react';
69
- import { token } from '@atlaskit/tokens';
70
- const styles = cssMap({
71
- root: {
72
- width: '16rem',
73
- },
74
- blackBorder: {
75
- border: '1px solid black',
76
- borderRadius: token('border.radius.100', '3px'),
77
- },
78
- });
79
- `,
80
- },
81
- {
82
- name: 'Custom import sources (subtractive)',
83
- code: `
84
- import { css } from '@compiled/react';
85
- import { color } from '../shared'
86
- const styles = css({
87
- color
88
- });
89
- `,
90
- options: [
91
- {
92
- importSources: [],
93
- },
94
- ],
95
- },
96
- {
97
- name: 'Custom allowed function',
98
- code: `
99
- import { css } from '@compiled/react';
100
- import { getColor } from 'my-package'
101
- const styles = css({
102
- color: getColor()
103
- });
104
- `,
105
- options: [
106
- {
107
- allowedFunctionCalls: [['my-package', 'getColor']],
108
- },
109
- ],
110
- },
111
- {
112
- name: 'Custom allowed dynamic key',
113
- code: `
114
- import { css } from '@compiled/react';
115
- import { colorKey } from 'my-package';
116
- const styles = css({
117
- [colorKey]: 'red',
118
- });
119
- `,
120
- options: [
121
- {
122
- allowedDynamicKeys: [['my-package', 'colorKey']],
123
- },
124
- ],
125
- },
126
- {
127
- name: 'Ignores type casts',
128
- code: `
129
- import type { CSSProperties } from 'react';
130
- import { css } from '@compiled/react';
131
-
132
- const Component = () => (
133
- <div
134
- style={
135
- {
136
- '--my-var': 'red',
137
- } as CSSProperties
138
- }
139
- />
140
- );
141
- `,
142
- options: [],
143
- },
144
- {
145
- name: 'Imported value in LHS of conditional expression in css prop',
146
- code: `
147
- import { css } from '@compiled/react';
148
- import { ff } from '@atlassian/jira-feature-flagging';
149
- import { IS_FF_ENABLED } from '../shared';
150
-
151
- const baseStyles = css({ margin: 0 });
152
- const styles = css({ color: token('color.text') });
153
- const stylesFF = css({ color: token('color.text.danger') });
154
-
155
- const Component = () => (
156
- <>
157
- <div css={IS_FF_ENABLED ? stylesFF : styles} />
158
- <div css={[baseStyles, IS_FF_ENABLED ? stylesFF : styles]} />
159
- <div css={ff('my-feature-flag') ? stylesFF : styles} />
160
- <div css={[baseStyles, ff('my-feature-flag') ? stylesFF : styles]} />
161
- </>
162
- );
163
- `,
164
- },
165
- {
166
- name: 'Imported value as entire LHS of logical expression in css prop',
167
- code: `
168
- import { css } from '@compiled/react';
169
- import { ff } from '@atlassian/jira-feature-flagging';
170
- import { IS_FF_ENABLED } from '../shared';
171
-
172
- const baseStyles = css({ margin: 0 });
173
- const stylesFF = css({ color: token('color.text.danger') });
174
-
175
- const Component = () => (
176
- <>
177
- <div css={IS_FF_ENABLED && stylesFF} />
178
- <div css={[baseStyles, IS_FF_ENABLED && stylesFF]} />
179
- <div css={ff('my-feature-flag') && stylesFF} />
180
- <div css={[baseStyles, ff('my-feature-flag') && stylesFF]} />
181
- </>
182
- );
183
- `,
184
- },
185
- {
186
- name: 'Imported value in LHS of conditional expression in style prop',
187
- code: `
188
- import { css } from '@compiled/react';
189
- import { ff } from '@atlassian/jira-feature-flagging';
190
- import { IS_FF_ENABLED } from '../shared';
191
-
192
- const Component = (props: { width: number }) => (
193
- <>
194
- <div style={{ width: IS_FF_ENABLED ? Math.abs(width) : width }} />
195
- <div style={{ width: ff('my-feature-flag') ? Math.abs(width) : width }} />
196
- </>
197
- );
198
- `,
199
- },
200
- {
201
- name: 'Non-computed member access that collides with imported name',
202
- code: `
203
- import { abs } from '../shared';
204
-
205
- const Component = (props: { width: number }) => (
206
- <div style={{ width: Math.abs(width) }} />
207
- );
208
- `,
209
- },
210
- {
211
- name: 'Non-computed property key that collides with imported name',
212
- code: `
213
- import { css } from '@compiled/react';
214
- import { color } from '../shared';
215
-
216
- const styles = css({
217
- color: token('color.text'),
218
- });
219
-
220
- const Component = (props: { color: string }) => (
221
- <div
222
- css={styles}
223
- style={{ color: props.color }}
224
- />
225
- );
226
- `,
227
- },
228
- ],
229
- invalid: [
230
- {
231
- name: 'Importing spreadElement',
232
- code: `
233
- import { css } from '@compiled/react';
234
- import { importedStyles } from '../shared';
235
- const styles = css({
236
- ...importedStyles,
237
- color: 'red',
238
- });
239
- `,
240
- errors: [{ messageId: 'no-imported-style-values' }],
241
- },
242
- {
243
- name: 'Importing functions to use within css',
244
- code: `
245
- import { css } from '@compiled/react';
246
- import { getColor } from '@mui/theme';
247
- import { colorKey } from '../shared';
248
- const styles = css({
249
- [colorKey]: getColor('red'),
250
- });
251
- `,
252
- errors: [
253
- { messageId: 'no-imported-style-values' },
254
- { messageId: 'no-imported-style-values' },
255
- ],
256
- },
257
- {
258
- name: 'Importing objects to use within css',
259
- code: `
260
- import { css } from '@compiled/react';
261
- import { colors } from '@mui/theme';
262
- const styles = css({
263
- background: colors['red'],
264
- });
265
- `,
266
- errors: [{ messageId: 'no-imported-style-values' }],
267
- },
268
- {
269
- name: 'Importing variables to use within template literal',
270
- code: `
271
- import { css } from '@compiled/react';
272
- import { HEIGHT } from '../shared';
273
- const styles = css({
274
- height: \`\${HEIGHT}px\`,
275
- });
276
- `,
277
- errors: [{ messageId: 'no-imported-style-values' }],
278
- },
279
- {
280
- name: 'Importing variables to within conditional expression',
281
- code: `
282
- import { css } from '@compiled/react';
283
- import { ff } from '@atlaskit/ff';
284
- import { HEIGHT } from '../shared';
285
- const styles = css({
286
- width: ff('…') ? \`\${HEIGHT}px\` : undefined,
287
- });
288
- `,
289
- errors: [
290
- { messageId: 'no-imported-style-values' },
291
- { messageId: 'no-imported-style-values' },
292
- ],
293
- },
294
- {
295
- name: 'Invalid styled component',
296
- code: `
297
- import { styled } from '@compiled/react';
298
- import { HEIGHT, importedStyles, getWidth } from '../shared';
299
-
300
- const randomVar = 10;
301
-
302
- const Component = styled.div({
303
- ...importedStyles,
304
- height: \`\${HEIGHT}px\`,
305
- width: getWidth(10),
306
- });
307
- `,
308
- errors: [
309
- { messageId: 'no-imported-style-values' },
310
- { messageId: 'no-imported-style-values' },
311
- { messageId: 'no-imported-style-values' },
312
- ],
313
- },
314
- {
315
- name: 'Invalid cssMap call',
316
- code: `
317
- import { cssMap } from '@compiled/react';
318
- import { textColor, bgColor } from '../shared';
319
-
320
- const styles = cssMap({
321
- text: { color: textColor },
322
- bg: { background: bgColor },
323
- });
324
- `,
325
- errors: [
326
- { messageId: 'no-imported-style-values' },
327
- { messageId: 'no-imported-style-values' },
328
- ],
329
- },
330
- {
331
- name: 'Invalid style composition in css prop',
332
- code: `
333
- import { css } from '@compiled/react';
334
- import { buttonStyles } from '../shared';
335
-
336
- const styles = css({
337
- color: 'red',
338
- });
339
-
340
- export default () => <div css={[styles, buttonStyles]} />;
341
- `,
342
- errors: [{ messageId: 'no-imported-style-values' }],
343
- },
344
- {
345
- name: 'Importing value within style prop',
346
- code: `
347
- import { importedWidth } from '../shared';
348
-
349
- export default () => <div style={{ width: importedWidth }} />;
350
- `,
351
- errors: [{ messageId: 'no-imported-style-values' }],
352
- },
353
- {
354
- name: 'Importing member expression',
355
- code: `
356
- import { hello } from 'package';
357
- import { css } from '@compiled/react';
358
-
359
- const styles = css({
360
- color: hello.world,
361
- });
362
- `,
363
- errors: [{ messageId: 'no-imported-style-values' }],
364
- },
365
- {
366
- name: 'Imported value in LHS of conditional expression in style declaration',
367
- code: `
368
- import { css } from '@compiled/react';
369
- import { ff } from '@atlassian/jira-feature-flagging';
370
- import { IS_FF_ENABLED } from '../shared';
371
-
372
- const stylesA = css({
373
- color: IS_FF_ENABLED ? token('color.text.danger'): token('color.text'),
374
- });
375
-
376
- const stylesB = css({
377
- color: ff('my-feature-flag') ? token('color.text.danger') : token('color.text'),
378
- });
379
- `,
380
- errors: [
381
- { messageId: 'no-imported-style-values', line: 7 },
382
- { messageId: 'no-imported-style-values', line: 11 },
383
- ],
384
- },
385
- {
386
- name: 'Imported value in RHS of conditional expression in css prop',
387
- code: `
388
- import { css } from '@compiled/react';
389
- import { ff } from '@atlassian/jira-feature-flagging';
390
- import { IS_FF_ENABLED, stylesFF } from '../shared';
391
-
392
- const baseStyles = css({ margin: 0 });
393
- const styles = css({ color: token('color.text' )});
394
-
395
- const Component = () => (
396
- <>
397
- <div css={IS_FF_ENABLED ? stylesFF : styles} />
398
- <div css={[baseStyles, IS_FF_ENABLED ? stylesFF : styles]} />
399
- <div css={ff('my-feature-flag') ? stylesFF : styles} />
400
- <div css={[baseStyles, ff('my-feature-flag') ? stylesFF : styles]} />
401
- </>
402
- );
403
- `,
404
- errors: [
405
- { messageId: 'no-imported-style-values', line: 11 },
406
- { messageId: 'no-imported-style-values', line: 12 },
407
- { messageId: 'no-imported-style-values', line: 13 },
408
- { messageId: 'no-imported-style-values', line: 14 },
409
- ],
410
- },
411
- {
412
- name: 'Imported value in RHS of logical expression in css prop',
413
- code: `
414
- import { css } from '@compiled/react';
415
- import { ff } from '@atlassian/jira-feature-flagging';
416
- import { IS_FF_ENABLED, stylesFF } from '../shared';
417
-
418
- const baseStyles = css({ margin: 0 });
419
- const styles = css({ color: token('color.text' )});
420
-
421
- const Component = () => (
422
- <>
423
- <div css={IS_FF_ENABLED && stylesFF} />
424
- <div css={[baseStyles, IS_FF_ENABLED && stylesFF]} />
425
- <div css={ff('my-feature-flag') && stylesFF} />
426
- <div css={[baseStyles, ff('my-feature-flag') && stylesFF]} />
427
- </>
428
- );
429
- `,
430
- errors: [
431
- { messageId: 'no-imported-style-values', line: 11 },
432
- { messageId: 'no-imported-style-values', line: 12 },
433
- { messageId: 'no-imported-style-values', line: 13 },
434
- { messageId: 'no-imported-style-values', line: 14 },
435
- ],
436
- },
437
- {
438
- name: 'Imported value in RHS of conditional expression in style prop',
439
- code: `
440
- import { css } from '@compiled/react';
441
- import { ff } from '@atlassian/jira-feature-flagging';
442
- import { IS_FF_ENABLED, abs } from '../shared';
443
-
444
- const Component = (props: { width: number }) => (
445
- <>
446
- <div style={{ width: IS_FF_ENABLED ? abs(width) : width }} />
447
- <div style={{ width: ff('my-feature-flag') ? abs(width) : width }} />
448
- </>
449
- );
450
- `,
451
- errors: [
452
- { messageId: 'no-imported-style-values', line: 8 },
453
- { messageId: 'no-imported-style-values', line: 9 },
454
- ],
455
- },
456
- {
457
- name: 'Computed member access with imported name',
458
- code: `
459
- import { abs } from '../shared';
460
-
461
- const Component = (props: { width: number }) => (
462
- <div style={{ width: Math[abs](width) }} />
463
- );
464
- `,
465
- errors: [{ messageId: 'no-imported-style-values' }],
466
- },
467
- {
468
- name: 'Computed property key with imported name',
469
- code: `
470
- import { css } from '@compiled/react';
471
- import { color } from '../shared';
472
-
473
- const styles = css({
474
- [color]: token('color.text'),
475
- });
476
-
477
- const Component = (props: { color: string }) => (
478
- <div
479
- css={styles}
480
- style={{ [color]: props.color }}
481
- />
482
- );
483
- `,
484
- errors: [
485
- { messageId: 'no-imported-style-values' },
486
- { messageId: 'no-imported-style-values' },
487
- ],
488
- },
489
- ],
490
- },
491
- );