@atlaskit/eslint-plugin-ui-styling-standard 0.18.0 → 0.18.2

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 (140) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/rules/no-imported-style-values/index.js +36 -5
  3. package/dist/es2019/rules/no-imported-style-values/index.js +36 -5
  4. package/dist/esm/rules/no-imported-style-values/index.js +36 -5
  5. package/package.json +1 -1
  6. package/afm-cc/tsconfig.json +0 -28
  7. package/afm-jira/tsconfig.json +0 -27
  8. package/build/tsconfig.json +0 -18
  9. package/constellation/atlaskit-theme/usage.mdx +0 -132
  10. package/constellation/consistent-css-prop-usage/usage.mdx +0 -7
  11. package/constellation/convert-props-syntax/usage.mdx +0 -130
  12. package/constellation/enforce-style-prop/usage.mdx +0 -47
  13. package/constellation/index/migration-guide.mdx +0 -309
  14. package/constellation/index/overview.mdx +0 -250
  15. package/constellation/index/props.mdx +0 -30
  16. package/constellation/local-cx-xcss/usage.mdx +0 -53
  17. package/constellation/no-array-arguments/usage.mdx +0 -49
  18. package/constellation/no-classname-prop/usage.mdx +0 -49
  19. package/constellation/no-container-queries/usage.mdx +0 -101
  20. package/constellation/no-css-tagged-template-expression/usage.mdx +0 -8
  21. package/constellation/no-dynamic-styles/usage.mdx +0 -130
  22. package/constellation/no-empty-styled-expression/usage.mdx +0 -8
  23. package/constellation/no-exported-css/usage.mdx +0 -8
  24. package/constellation/no-exported-keyframes/usage.mdx +0 -8
  25. package/constellation/no-exported-styles/usage.mdx +0 -87
  26. package/constellation/no-global-styles/usage.mdx +0 -60
  27. package/constellation/no-important-styles/usage.mdx +0 -33
  28. package/constellation/no-imported-style-values/usage.mdx +0 -157
  29. package/constellation/no-invalid-css-map/usage.mdx +0 -8
  30. package/constellation/no-js-xcss/usage.mdx +0 -7
  31. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -8
  32. package/constellation/no-nested-selectors/usage.mdx +0 -95
  33. package/constellation/no-styled/usage.mdx +0 -92
  34. package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -8
  35. package/constellation/no-suppress-xcss/usage.mdx +0 -28
  36. package/constellation/no-unsafe-selectors/usage.mdx +0 -370
  37. package/constellation/no-unsafe-values/usage.mdx +0 -318
  38. package/constellation/use-compiled/usage.mdx +0 -54
  39. package/index.js +0 -24
  40. package/scripts/codegen.tsx +0 -373
  41. package/src/index.codegen.tsx +0 -14
  42. package/src/index.tsx +0 -1
  43. package/src/presets/all.codegen.tsx +0 -79
  44. package/src/presets/recommended.codegen.tsx +0 -79
  45. package/src/rules/TEMPLATE.md +0 -29
  46. package/src/rules/__tests__/utils/_tester.tsx +0 -40
  47. package/src/rules/atlaskit-theme/README.md +0 -130
  48. package/src/rules/atlaskit-theme/__tests__/test.ts +0 -133
  49. package/src/rules/atlaskit-theme/index.ts +0 -134
  50. package/src/rules/convert-props-syntax/README.md +0 -128
  51. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +0 -76
  52. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +0 -584
  53. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +0 -140
  54. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +0 -69
  55. package/src/rules/convert-props-syntax/index.tsx +0 -414
  56. package/src/rules/enforce-style-prop/README.md +0 -45
  57. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +0 -243
  58. package/src/rules/enforce-style-prop/index.tsx +0 -172
  59. package/src/rules/external-rules.tsx +0 -177
  60. package/src/rules/index.codegen.tsx +0 -42
  61. package/src/rules/local-cx-xcss/README.md +0 -51
  62. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +0 -102
  63. package/src/rules/local-cx-xcss/index.tsx +0 -62
  64. package/src/rules/no-array-arguments/README.md +0 -47
  65. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +0 -107
  66. package/src/rules/no-array-arguments/index.tsx +0 -86
  67. package/src/rules/no-classname-prop/README.md +0 -47
  68. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +0 -39
  69. package/src/rules/no-classname-prop/index.tsx +0 -34
  70. package/src/rules/no-container-queries/README.md +0 -99
  71. package/src/rules/no-container-queries/__tests__/rule.test.tsx +0 -139
  72. package/src/rules/no-container-queries/index.tsx +0 -94
  73. package/src/rules/no-dynamic-styles/README.md +0 -128
  74. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +0 -135
  75. package/src/rules/no-dynamic-styles/index.tsx +0 -60
  76. package/src/rules/no-exported-styles/README.md +0 -85
  77. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +0 -216
  78. package/src/rules/no-exported-styles/index.tsx +0 -52
  79. package/src/rules/no-global-styles/README.md +0 -58
  80. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +0 -33
  81. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +0 -46
  82. package/src/rules/no-global-styles/index.tsx +0 -82
  83. package/src/rules/no-important-styles/README.md +0 -31
  84. package/src/rules/no-important-styles/__tests__/rule.test.tsx +0 -165
  85. package/src/rules/no-important-styles/index.tsx +0 -70
  86. package/src/rules/no-imported-style-values/README.md +0 -155
  87. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +0 -491
  88. package/src/rules/no-imported-style-values/index.tsx +0 -188
  89. package/src/rules/no-nested-selectors/README.md +0 -93
  90. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +0 -335
  91. package/src/rules/no-nested-selectors/index.tsx +0 -99
  92. package/src/rules/no-styled/README.md +0 -90
  93. package/src/rules/no-styled/__tests__/rule.test.tsx +0 -73
  94. package/src/rules/no-styled/index.tsx +0 -45
  95. package/src/rules/no-unsafe-selectors/README.md +0 -368
  96. package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +0 -368
  97. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +0 -57
  98. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +0 -73
  99. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +0 -40
  100. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +0 -101
  101. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +0 -131
  102. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +0 -132
  103. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +0 -25
  104. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +0 -35
  105. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +0 -257
  106. package/src/rules/no-unsafe-selectors/constants.tsx +0 -91
  107. package/src/rules/no-unsafe-selectors/index.tsx +0 -198
  108. package/src/rules/no-unsafe-selectors/lint-selector.tsx +0 -155
  109. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +0 -55
  110. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +0 -226
  111. package/src/rules/no-unsafe-values/README.md +0 -316
  112. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +0 -27
  113. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +0 -37
  114. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +0 -229
  115. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +0 -267
  116. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +0 -52
  117. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +0 -106
  118. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +0 -44
  119. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +0 -48
  120. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +0 -75
  121. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +0 -121
  122. package/src/rules/no-unsafe-values/index.tsx +0 -94
  123. package/src/rules/no-unsafe-values/messages.tsx +0 -86
  124. package/src/rules/no-unsafe-values/utils.tsx +0 -387
  125. package/src/rules/use-compiled/README.md +0 -52
  126. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +0 -73
  127. package/src/rules/use-compiled/__tests__/css.test.tsx +0 -126
  128. package/src/rules/use-compiled/__tests__/imports.test.tsx +0 -158
  129. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +0 -140
  130. package/src/rules/use-compiled/__tests__/pragma.test.tsx +0 -108
  131. package/src/rules/use-compiled/__tests__/styled.test.tsx +0 -114
  132. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +0 -15
  133. package/src/rules/use-compiled/index.tsx +0 -252
  134. package/src/rules/use-compiled/is-safe.tsx +0 -159
  135. package/src/rules/use-compiled/utils.tsx +0 -33
  136. package/src/rules/utils/create-rule-with-typed-config.tsx +0 -86
  137. package/src/rules/utils/create-rule.tsx +0 -13
  138. package/tsconfig.app.json +0 -47
  139. package/tsconfig.dev.json +0 -45
  140. package/tsconfig.json +0 -25
@@ -1,94 +0,0 @@
1
- import { createLintRule } from '../utils/create-rule';
2
- import {
3
- isCss,
4
- getImportSources,
5
- isStyled,
6
- isKeyframes,
7
- isCssMap,
8
- isXcss,
9
- } from '@atlaskit/eslint-utils/is-supported-import';
10
- import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
11
- import { Linter } from './utils';
12
- import { messages } from './messages';
13
-
14
- const schema: JSONSchema4 = [
15
- {
16
- type: 'object',
17
- additionalProperties: false,
18
- properties: {
19
- importSources: {
20
- type: 'array',
21
- items: { type: 'string' },
22
- uniqueItems: true,
23
- },
24
- allowedFunctionCalls: {
25
- type: 'array',
26
- items: {
27
- type: 'array',
28
- minItems: 2,
29
- maxItems: 2,
30
- items: [{ type: 'string' }, { type: 'string' }],
31
- },
32
- uniqueItems: true,
33
- },
34
- allowedDynamicKeys: {
35
- type: 'array',
36
- items: {
37
- type: 'array',
38
- minItems: 2,
39
- maxItems: 2,
40
- items: [{ type: 'string' }, { type: 'string' }],
41
- },
42
- uniqueItems: true,
43
- },
44
- },
45
- },
46
- ];
47
-
48
- export const rule = createLintRule({
49
- meta: {
50
- name: 'no-unsafe-values',
51
- docs: {
52
- description: 'Disallows styles that are difficult/impossible to statically anaylze.',
53
- recommended: true,
54
- severity: 'error',
55
- },
56
- messages,
57
- type: 'problem',
58
- schema,
59
- },
60
- create(context) {
61
- const importSources = getImportSources(context);
62
-
63
- return {
64
- CallExpression(node) {
65
- const { references } = context.getScope();
66
-
67
- if (
68
- !isCss(node.callee, references, importSources) &&
69
- !isStyled(node.callee, references, importSources) &&
70
- !isKeyframes(node.callee, references, importSources) &&
71
- !isCssMap(node.callee, references, importSources) &&
72
- !isXcss(node.callee, references, importSources)
73
- ) {
74
- return;
75
- }
76
-
77
- if (
78
- isStyled(node.callee, references, importSources) &&
79
- (node.parent.type === 'CallExpression' || node.parent.type === 'TaggedTemplateExpression')
80
- ) {
81
- /**
82
- * If it is of the form styled(Base)({}) we don't want to lint the inner function arguments.
83
- */
84
- return;
85
- }
86
-
87
- const linter = new Linter(context, node);
88
- linter.run();
89
- },
90
- };
91
- },
92
- });
93
-
94
- export default rule;
@@ -1,86 +0,0 @@
1
- import outdent from 'outdent';
2
-
3
- const whereToGetHelp =
4
- "If you think this should be allowed, or if you're running into issues, reach out in #help-ui-styling-standard";
5
-
6
- export const messages = {
7
- 'no-array-values': outdent`
8
- Arrays are not allowed in style objects. Support is inconsistent between styling libraries.
9
-
10
- Compose styles with the css prop instead.
11
-
12
- ${whereToGetHelp}
13
- `,
14
-
15
- 'no-conditional-values': outdent`
16
- Conditional expressions are not allowed in style objects.
17
-
18
- Conditionally apply styles with the css prop instead.
19
-
20
- ${whereToGetHelp}
21
- `,
22
-
23
- 'no-dynamic-keys': outdent`
24
- Dynamic keys are not allowed in style objects.
25
-
26
- ${whereToGetHelp}
27
- `,
28
-
29
- 'no-function-calls': outdent`
30
- Function calls are not allowed in style objects.
31
-
32
- ${whereToGetHelp}
33
- `,
34
-
35
- 'no-identifier-arguments': outdent`
36
- Variable arguments are not allowed.
37
-
38
- Inline the object value, or compose styles with the css prop instead.
39
-
40
- ${whereToGetHelp}
41
- `,
42
-
43
- 'no-object-access': outdent`
44
- Accessing object values is not allowed in style objects.
45
-
46
- If you are accessing the component's props, use the style prop to apply dynamic values instead.
47
-
48
- ${whereToGetHelp}
49
- `,
50
-
51
- 'no-object-references': outdent`
52
- Referencing objects is not allowed in style objects.
53
-
54
- Inline the object value instead.
55
-
56
- ${whereToGetHelp}
57
- `,
58
-
59
- 'no-spread-elements': outdent`
60
- Spread elements are not allowed in style objects.
61
-
62
- Compose styles with the css prop instead.
63
-
64
- ${whereToGetHelp}
65
- `,
66
-
67
- // Fallback case if a more specific message is not applicable
68
- 'no-unsafe-values': outdent`
69
- Unsafe values are not allowed in style objects.
70
-
71
- ${whereToGetHelp}
72
- `,
73
-
74
- 'no-variables': outdent`
75
- Variables are not allowed in style objects, unless they:
76
-
77
- - Have a simple, static value.
78
- - Are defined in the same file.
79
-
80
- Use the style prop to apply dynamic values instead.
81
-
82
- ${whereToGetHelp}
83
- `,
84
- };
85
-
86
- export type MessageId = keyof typeof messages;
@@ -1,387 +0,0 @@
1
- import type {
2
- CallExpression,
3
- Expression,
4
- Identifier,
5
- Property,
6
- ObjectExpression,
7
- Node,
8
- } from 'estree-jsx';
9
- import type { Rule } from 'eslint';
10
-
11
- import {
12
- getAllowedDynamicKeys,
13
- getAllowedFunctionCalls,
14
- isAllowListedVariable,
15
- type AllowList,
16
- } from '@atlaskit/eslint-utils/allowed-function-calls';
17
- import type { Variable } from 'eslint-scope';
18
- import { findIdentifierNode } from '@atlaskit/eslint-utils/find-identifier-node';
19
- import { findVariable } from '@atlaskit/eslint-utils/find-variable';
20
-
21
- import type { MessageId } from './messages';
22
-
23
- function isReferenceToCssVar(variable: Variable) {
24
- const definitions = variable.defs;
25
-
26
- return definitions.every((definition) => {
27
- if (definition.type !== 'Variable') {
28
- return false;
29
- }
30
-
31
- const initializer = definition.node.init;
32
- if (!initializer) {
33
- return false;
34
- }
35
-
36
- return (
37
- initializer.type === 'Literal' &&
38
- typeof initializer.value === 'string' &&
39
- initializer.value.startsWith('--')
40
- );
41
- });
42
- }
43
-
44
- export class Linter {
45
- private readonly allowedDynamicKeys: AllowList;
46
- private readonly allowedFunctionCalls: AllowList;
47
-
48
- constructor(
49
- private readonly context: Rule.RuleContext,
50
- private readonly baseNode: CallExpression,
51
- ) {
52
- this.allowedDynamicKeys = getAllowedDynamicKeys(context.options);
53
- this.allowedFunctionCalls = getAllowedFunctionCalls(context.options);
54
- }
55
-
56
- /**
57
- * Wrapper around `context.report` to provide type checking on the message ID.
58
- */
59
- private report(descriptor: { node: Node; messageId: MessageId }) {
60
- this.context.report(descriptor);
61
- }
62
-
63
- /**
64
- * Fallback case to lint any identifier that is not otherwise handled.
65
- */
66
- private lintUnhandledIdentifier(identifier: Identifier) {
67
- this.report({ node: identifier, messageId: 'no-variables' });
68
- }
69
-
70
- private lintIdentifier(value: Identifier) {
71
- if (value.name === 'undefined') {
72
- /**
73
- * `undefined` gets caught implicitly anyway by other checks below,
74
- * but we are explicitly handling it here.
75
- *
76
- * We could potentially introduce a distinct message for it as well.
77
- */
78
- this.lintUnhandledIdentifier(value);
79
- return;
80
- }
81
-
82
- const variable = findVariable({
83
- identifier: value,
84
- sourceCode: this.context.getSourceCode(),
85
- });
86
- if (!variable) {
87
- this.lintUnhandledIdentifier(value);
88
- return;
89
- }
90
-
91
- /**
92
- * Allows using whitelisted imported values
93
- */
94
- if (
95
- isAllowListedVariable({
96
- allowList: this.allowedFunctionCalls,
97
- variable,
98
- })
99
- ) {
100
- return;
101
- }
102
-
103
- const definitions = variable.defs;
104
- if (definitions.length === 0) {
105
- this.lintUnhandledIdentifier(value);
106
- return;
107
- }
108
-
109
- definitions.forEach((definition) => {
110
- if (definition.type === 'Variable') {
111
- const initializer = definition.node.init;
112
- if (!initializer) {
113
- this.lintUnhandledIdentifier(value);
114
- return;
115
- }
116
-
117
- /**
118
- * Variables can be used if they resolve to a literal.
119
- */
120
- if (initializer.type === 'Literal') {
121
- return;
122
- }
123
-
124
- /**
125
- * Not allowing tagged template expressions through variables.
126
- */
127
- if (initializer.type === 'TaggedTemplateExpression') {
128
- this.report({ node: value, messageId: 'no-function-calls' });
129
- return;
130
- }
131
-
132
- /**
133
- * Variables can be used if they resolve to an allowed function call.
134
- */
135
- if (initializer.type === 'CallExpression') {
136
- if (this.isAllowedFunctionCall(initializer)) {
137
- return;
138
- }
139
- this.report({ node: value, messageId: 'no-function-calls' });
140
- return;
141
- }
142
-
143
- if (initializer.type === 'TemplateLiteral') {
144
- for (const expression of initializer.expressions) {
145
- this.lintValue(expression);
146
- }
147
- return;
148
- }
149
-
150
- /**
151
- * This branch is only here for clarity.
152
- *
153
- * We could fallback to `no-variables` for it too.
154
- */
155
- if (initializer.type === 'ObjectExpression') {
156
- this.report({ node: value, messageId: 'no-object-references' });
157
- return;
158
- }
159
- }
160
-
161
- this.lintUnhandledIdentifier(value);
162
- });
163
- }
164
-
165
- private isAllowedDynamicKey(expression: Expression) {
166
- const identifier = findIdentifierNode(expression);
167
- if (!identifier) {
168
- return false;
169
- }
170
-
171
- const variable = findVariable({
172
- identifier,
173
- sourceCode: this.context.getSourceCode(),
174
- });
175
- if (!variable) {
176
- return false;
177
- }
178
-
179
- return (
180
- isReferenceToCssVar(variable) ||
181
- isAllowListedVariable({ allowList: this.allowedDynamicKeys, variable })
182
- );
183
- }
184
-
185
- private lintKey(property: Property) {
186
- /**
187
- * If it's not computed then it must be a plain string.
188
- *
189
- * Private identifiers cannot be computed,
190
- * but we need the extra check for type narrowing.
191
- */
192
- if (!property.computed || property.key.type === 'PrivateIdentifier') {
193
- return;
194
- }
195
-
196
- /**
197
- * Some dynamic keys are explicitly allowed.
198
- */
199
- if (this.isAllowedDynamicKey(property.key)) {
200
- return;
201
- }
202
-
203
- this.report({ node: property.key, messageId: 'no-dynamic-keys' });
204
- }
205
-
206
- private isAllowedFunctionCall(value: CallExpression) {
207
- const identifier = findIdentifierNode(value);
208
- if (!identifier) {
209
- return false;
210
- }
211
-
212
- const variable = findVariable({
213
- identifier,
214
- sourceCode: this.context.getSourceCode(),
215
- });
216
- if (!variable) {
217
- return false;
218
- }
219
-
220
- return isAllowListedVariable({
221
- allowList: this.allowedFunctionCalls,
222
- variable,
223
- });
224
- }
225
-
226
- private lintFunctionCall(value: CallExpression) {
227
- if (this.isAllowedFunctionCall(value)) {
228
- return;
229
- }
230
-
231
- this.report({ node: value, messageId: 'no-function-calls' });
232
- }
233
-
234
- private lintObjectExpression(expression: ObjectExpression) {
235
- for (const property of expression.properties) {
236
- if (property.type === 'SpreadElement') {
237
- this.report({
238
- node: property,
239
- messageId: 'no-spread-elements',
240
- });
241
- } else {
242
- this.lintKey(property);
243
- this.lintValue(property.value);
244
- }
245
- }
246
- }
247
-
248
- private lintUnhandledValue(value: Node) {
249
- /**
250
- * Default to blocking value if it isn't explictly handled.
251
- */
252
- this.report({ node: value, messageId: 'no-unsafe-values' });
253
- }
254
-
255
- private lintValue(value: Property['value']): void {
256
- /**
257
- * Literals are always allowed by this rule.
258
- */
259
- if (value.type === 'Literal') {
260
- return;
261
- }
262
-
263
- /**
264
- * Allow negative numbers.
265
- */
266
- if (
267
- value.type === 'UnaryExpression' &&
268
- value.operator === '-' &&
269
- value.argument.type === 'Literal'
270
- ) {
271
- return;
272
- }
273
-
274
- if (value.type === 'TemplateLiteral') {
275
- for (const expression of value.expressions) {
276
- this.lintValue(expression);
277
- }
278
- return;
279
- }
280
-
281
- if (value.type === 'ConditionalExpression' || value.type === 'LogicalExpression') {
282
- this.report({ node: value, messageId: 'no-conditional-values' });
283
- return;
284
- }
285
-
286
- if (value.type === 'BinaryExpression') {
287
- this.lintValue(value.left);
288
- this.lintValue(value.right);
289
- return;
290
- }
291
-
292
- if (value.type === 'ObjectExpression') {
293
- this.lintObjectExpression(value);
294
- return;
295
- }
296
-
297
- if (value.type === 'Identifier') {
298
- this.lintIdentifier(value);
299
- return;
300
- }
301
-
302
- if (value.type === 'TaggedTemplateExpression') {
303
- this.report({ node: value, messageId: 'no-function-calls' });
304
- return;
305
- }
306
-
307
- if (value.type === 'CallExpression') {
308
- this.lintFunctionCall(value);
309
- return;
310
- }
311
-
312
- if (value.type === 'ArrowFunctionExpression' || value.type === 'FunctionExpression') {
313
- /**
314
- * Function values are handled by `no-dynamic-styles` instead
315
- */
316
- return;
317
- }
318
-
319
- if (value.type === 'MemberExpression') {
320
- this.report({ node: value, messageId: 'no-object-access' });
321
- return;
322
- }
323
-
324
- if (value.type === 'ArrayExpression') {
325
- this.report({ node: value, messageId: 'no-array-values' });
326
- return;
327
- }
328
-
329
- this.lintUnhandledValue(value);
330
- }
331
-
332
- private lintArgument(argument: CallExpression['arguments'][number]) {
333
- if (argument.type === 'ArrowFunctionExpression') {
334
- if (argument.body.type === 'ObjectExpression') {
335
- // Something in this form:
336
- //
337
- // const styles = styled.div(
338
- // (props) => ({ color: props.height }),
339
- // );
340
- this.lintArgument(argument.body);
341
- }
342
- return;
343
- }
344
-
345
- if (argument.type === 'ArrayExpression') {
346
- for (const element of argument.elements) {
347
- if (element === null) {
348
- continue;
349
- }
350
- this.lintArgument(element);
351
- }
352
- return;
353
- }
354
-
355
- if (argument.type === 'ObjectExpression') {
356
- this.lintObjectExpression(argument);
357
- return;
358
- }
359
-
360
- if (argument.type === 'CallExpression') {
361
- this.lintFunctionCall(argument);
362
- return;
363
- }
364
-
365
- if (argument.type === 'ConditionalExpression' || argument.type === 'LogicalExpression') {
366
- this.report({ node: argument, messageId: 'no-conditional-values' });
367
- return;
368
- }
369
-
370
- if (argument.type === 'Identifier' || argument.type === 'MemberExpression') {
371
- this.report({ node: argument, messageId: 'no-identifier-arguments' });
372
- return;
373
- }
374
-
375
- this.lintUnhandledValue(argument);
376
- }
377
-
378
- private lintArguments(args: CallExpression['arguments']) {
379
- for (const argument of args) {
380
- this.lintArgument(argument);
381
- }
382
- }
383
-
384
- run(): void {
385
- this.lintArguments(this.baseNode.arguments);
386
- }
387
- }
@@ -1,52 +0,0 @@
1
- Blocks CSS-in-JS libraries other than `@compiled/react`, including Emotion and styled-components.
2
-
3
- **WARNING** It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on
4
- the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the
5
- autofixer has been disabled by default, but it may be useful to enable to empower a migration.
6
-
7
- ## Examples
8
-
9
- ### Incorrect
10
-
11
- ```tsx
12
- /** @jsx jsx */
13
- import { css } from '@emotion/core';
14
- import { jsx } from '@emotion/react';
15
- import styled from '@emotion/styled';
16
- ```
17
-
18
- ```tsx
19
- import styled, { css } from 'styled-components';
20
- ```
21
-
22
- ### Correct
23
-
24
- We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with
25
- `@compiled/react` when working with custom or native code.
26
-
27
- ```tsx
28
- /** @jsx jsx */
29
- import { jsx, css, styled } from '@compiled/react';
30
-
31
- const styles = css({ color: 'var(--ds-color-text)' });
32
- export default () => <div css={styles}>…</div>;
33
- ```
34
-
35
- ```tsx
36
- import { xcss, Box } from '@atlaskit/primitives';
37
-
38
- const styles = xcss({ color: 'color.text' });
39
- export default () => <Box xcss={styles}>…</Box>;
40
- ```
41
-
42
- ## Options
43
-
44
- ### `canAutoFix: boolean`
45
-
46
- Determines whether or not the autofixer is enabled.
47
-
48
- Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the
49
- same component.
50
-
51
- Even when enabled, the autofixer will only convert usages that are deemed safe. Currently this is
52
- limited to purely static styles where all keys and values are simple literals.
@@ -1,73 +0,0 @@
1
- import type { RuleTester } from 'eslint';
2
- import { tester } from '../../__tests__/utils/_tester';
3
- import rule from '../index';
4
-
5
- const invalid: RuleTester.InvalidTestCase[] = [
6
- {
7
- name: 'css API',
8
- code: `
9
- import { css } from '@emotion/react';
10
-
11
- const Component = css({
12
- color: 'red',
13
- });
14
- `,
15
- errors: [{ messageId: 'use-compiled' }],
16
- },
17
- {
18
- name: 'imports',
19
- code: `
20
- import { css as c, keyframes as kf } from '@emotion/core';
21
- `,
22
- errors: [{ messageId: 'use-compiled' }],
23
- },
24
- {
25
- name: `keyframes API`,
26
- code: `
27
- import { keyframes } from 'styled-components';
28
-
29
- const fadeIn = keyframes({
30
- from: {
31
- opacity: 0,
32
- },
33
- to: {
34
- opacity: 1,
35
- }
36
- });
37
- `,
38
- errors: [{ messageId: 'use-compiled' }],
39
- },
40
- {
41
- name: 'pragma fix',
42
- code: `
43
- /** @jsxImportSource @emotion/react */
44
-
45
- import { css } from '@compiled/react';
46
- `,
47
- errors: [{ messageId: 'use-compiled' }],
48
- },
49
- {
50
- name: `styles are a plain object with literal values`,
51
- code: `
52
- import styled from '@emotion/styled';
53
-
54
- const Component = styled.div({
55
- color: 'red',
56
- });
57
- `,
58
- errors: [{ messageId: 'use-compiled' }],
59
- },
60
- ];
61
-
62
- tester.run('canAutoFix is not provided', rule, {
63
- valid: [],
64
- invalid,
65
- });
66
-
67
- tester.run('canAutoFix is false', rule, {
68
- valid: [],
69
- invalid: invalid.map((testCase) => ({
70
- ...testCase,
71
- options: [{ canAutoFix: false }],
72
- })),
73
- });