@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,69 +0,0 @@
1
- import { typescriptEslintTester } from '../../__tests__/utils/_tester';
2
- import rule from '../index';
3
-
4
- typescriptEslintTester.run(
5
- 'convert-props-syntax',
6
- // @ts-expect-error
7
- rule,
8
- {
9
- valid: [],
10
- invalid: [
11
- {
12
- name: 'disables autofixer for rest element in parameter',
13
- // Not sure if this would ever occur in a codebase, but we deliberately ignore it.
14
- code: `
15
- import styled from 'styled-components';
16
-
17
- styled.div({
18
- color: ({ ...restElement }) => restElement,
19
- });
20
- `,
21
- errors: [
22
- {
23
- messageId: 'unsupported-prop-syntax-no-autofixer',
24
- },
25
- ],
26
- },
27
- {
28
- name: 'disables autofixer for default value in parameter',
29
- code: `
30
- import styled from 'styled-components';
31
-
32
- styled.div({
33
- color: ({ myColor = '#fff' }) => myColor,
34
- backgroundColor: ({ myColor = '#aaa' }) => myColor,
35
- });
36
- `,
37
- errors: [
38
- {
39
- messageId: 'unsupported-prop-syntax-no-autofixer',
40
- },
41
- ],
42
- },
43
- {
44
- name: 'applies autofixer for nested selector',
45
- code: `
46
- import styled from 'styled-components';
47
-
48
- styled.div({
49
- img: {
50
- color: (props) => props.imgColor,
51
- },
52
- color: (props) => props.otherColor,
53
- });
54
- `,
55
- output: `
56
- import styled from 'styled-components';
57
-
58
- styled.div((props) => ({
59
- img: {
60
- color: props.imgColor,
61
- },
62
- color: props.otherColor,
63
- }));
64
- `,
65
- errors: [{ messageId: 'unsupported-prop-syntax' }],
66
- },
67
- ],
68
- },
69
- );
@@ -1,414 +0,0 @@
1
- import { analyze } from 'eslint-scope';
2
- import type {
3
- ArrowFunctionExpression,
4
- AssignmentProperty,
5
- CallExpression,
6
- Identifier,
7
- MemberExpression,
8
- ObjectExpression,
9
- } from 'estree-jsx';
10
- import { createLintRule } from '../utils/create-rule';
11
- import { isStyledComponents, isEmotion } from '@atlaskit/eslint-utils/is-supported-import';
12
- import type { Rule, Scope, SourceCode } from 'eslint';
13
- import ESTraverse from 'estraverse';
14
- import { isNodeOfType } from 'eslint-codemod-utils';
15
-
16
- type PropInfo = {
17
- /**
18
- * Name of the prop, e.g. props, backgroundColor.
19
- */
20
- propName: string;
21
- usages: (IdentifierWithParent | MemberExpressionWithParent)[];
22
- };
23
-
24
- type ValidPropsFound = {
25
- arrowFunctionExpression: ArrowFunctionExpression;
26
- props: PropInfo[];
27
- valid: true;
28
- };
29
-
30
- type IdentifierWithParent = Scope.Reference['identifier'] & Rule.NodeParentExtension;
31
-
32
- type MemberExpressionWithParent = MemberExpression & Rule.NodeParentExtension;
33
-
34
- /**
35
- * Represents some information about single line that contains some props, e.g.
36
- * the arrow function in
37
- *
38
- * color: (props) => `mix(${props.myColor}, #fff)`
39
- *
40
- * or about a destructuring assignment, e.g. the arrow function in
41
- *
42
- * color: ({ myColor, otherColor }) => someFunction(myColor, otherColor)
43
- *
44
- * or something that we don't recognise, or that we don't think is valid
45
- *
46
- * color: (props, someOtherVariable) => someOtherVariable
47
- */
48
- type PropsFound =
49
- | ValidPropsFound
50
- | {
51
- /**
52
- * Props use a syntax we don't recognise, or we don't think is valid...
53
- * or perhaps something unexpected happened in ESLint and we don't feel confident enough to try and autofix anything.
54
- */
55
- valid: false;
56
- };
57
-
58
- const standardizePropExpression = (
59
- sourceCode: SourceCode,
60
- expression: MemberExpression | Identifier,
61
- ): string | undefined => {
62
- const propsObjectName = 'props';
63
-
64
- if (expression.type === 'Identifier') {
65
- return `${propsObjectName}.${expression.name}`;
66
- }
67
-
68
- if (expression.type === 'MemberExpression' && expression.property.type === 'Identifier') {
69
- const propertyName = sourceCode.getText(expression.property);
70
- return `${propsObjectName}.${propertyName}`;
71
- }
72
-
73
- // Cannot safely process the expression, bail out!
74
- return undefined;
75
- };
76
-
77
- const parseArrowFunctionExpression = (
78
- expression: ArrowFunctionExpression,
79
- sourceCode: SourceCode,
80
- ): PropsFound => {
81
- if (expression.params.length !== 1) {
82
- return { valid: false };
83
- }
84
-
85
- const scopeManager = analyze(expression, {});
86
- const currentScope = scopeManager.acquire(expression);
87
-
88
- if (!currentScope) {
89
- return { valid: false };
90
- }
91
-
92
- const parameter = expression.params[0];
93
- const props: PropInfo[] = [];
94
-
95
- // Don't bother handling type annotations that appear in the parameters of arrow functions.
96
- //
97
- // This only applies if the ESLint rule is running under @typescript-eslint (not regular eslint), hence the roundabout way we use to check whether parameter.typeAnnotation exists or not.
98
- if ('typeAnnotation' in parameter && parameter.typeAnnotation) {
99
- return { valid: false };
100
- }
101
-
102
- if (parameter.type === 'ObjectPattern') {
103
- if (parameter.properties.some((value) => value.type === 'RestElement')) {
104
- return { valid: false };
105
- }
106
- const properties = parameter.properties as AssignmentProperty[];
107
-
108
- for (const property of properties) {
109
- const propertyValue = property.value;
110
- // Don't bother supporting other patterns like rest elements, default values...
111
- if (propertyValue.type !== 'Identifier') {
112
- return { valid: false };
113
- }
114
-
115
- const variable = currentScope.variables.find((varb) => varb.name === propertyValue.name);
116
-
117
- if (!variable || !variable.references || !variable.references.length) {
118
- // Something went wrong, best to just bail out.
119
- return { valid: false };
120
- }
121
-
122
- const propName = standardizePropExpression(sourceCode, propertyValue);
123
-
124
- if (!propName) {
125
- return { valid: false };
126
- }
127
-
128
- props.push({
129
- propName,
130
- usages: variable.references.map(
131
- (reference) => reference.identifier as IdentifierWithParent,
132
- ),
133
- });
134
- }
135
- } else if (parameter.type === 'Identifier') {
136
- const variable = currentScope.variables.find((varb) => varb.name === parameter.name);
137
-
138
- if (!variable || !variable.references || !variable.references.length) {
139
- // Something went wrong, best to just bail out.
140
- return { valid: false };
141
- }
142
-
143
- for (const reference of variable.references) {
144
- const memberExpression = (reference.identifier as IdentifierWithParent).parent;
145
- if (memberExpression.type !== 'MemberExpression') {
146
- // If reference.identifier.parent is not a member expression, that indicates
147
- // that we have a usage of the props argument that does NOT look like
148
- //
149
- // (props) => props.color
150
- //
151
- // e.g. we might have (props) => props['...'] or (props) => `${props}px` perhaps...
152
- //
153
- // We have no choice but to bail out because the syntax is not what we expect.
154
- return { valid: false };
155
- }
156
-
157
- const propName = standardizePropExpression(sourceCode, memberExpression);
158
-
159
- if (!propName) {
160
- return { valid: false };
161
- }
162
-
163
- props.push({
164
- propName,
165
- usages: [memberExpression],
166
- });
167
- }
168
- } else {
169
- // Bail out for any syntax we don't recognise.
170
- return { valid: false };
171
- }
172
-
173
- return { arrowFunctionExpression: expression, props, valid: true };
174
- };
175
-
176
- const lintArguments = (context: Rule.RuleContext, args: CallExpression['arguments']) => {
177
- for (const argument of args) {
178
- if (argument.type === 'ArrowFunctionExpression') {
179
- // styled.div((props) => ({ ... }))
180
- // styled.div(({ color, height }) => ({ ... }))
181
- //
182
- // Already in the form we want.
183
- continue;
184
- } else if (argument.type === 'ObjectExpression') {
185
- const allProps: PropsFound[] = [];
186
-
187
- // vvvvvvv
188
- // styled.div({ ... })
189
- for (const property of argument.properties) {
190
- if (property.type === 'SpreadElement') {
191
- // e.g.
192
- // styled.div({ color: 'blue', ...someStyles })
193
- //
194
- // If we have a spread element, we can no longer safely
195
- // transform this styled/css call without a lot more effort.
196
- //
197
- // Best to give up...
198
- return;
199
- } else {
200
- ESTraverse.traverse(property.value, {
201
- enter: function (node, _parent) {
202
- if (node.type === 'ArrowFunctionExpression') {
203
- const propNames = parseArrowFunctionExpression(node, context.getSourceCode());
204
-
205
- if (!propNames) {
206
- // We've encountered a CSS value we don't recognise, skip.
207
- return;
208
- }
209
-
210
- allProps.push(propNames);
211
- }
212
- },
213
- /**
214
- * This is needed to handle unknown node types. Otherwise an error is thrown.
215
- */
216
- fallback: 'iteration',
217
- });
218
- }
219
- }
220
-
221
- if (!allProps.length) {
222
- continue;
223
- }
224
-
225
- if (allProps.some((propUsage) => !propUsage.valid)) {
226
- context.report({
227
- node: argument,
228
- messageId: 'unsupported-prop-syntax-no-autofixer',
229
- });
230
-
231
- return;
232
- }
233
-
234
- context.report({
235
- node: argument,
236
- messageId: 'unsupported-prop-syntax',
237
- fix(fixer) {
238
- const sourceCode = context.getSourceCode();
239
- return fixPropsObjectUsages(
240
- fixer,
241
- sourceCode,
242
- argument,
243
- // The
244
- // allProps.some((propUsage) => !propUsage.valid)
245
- // condition above should have made this type assertion unnecessary...
246
- allProps as ValidPropsFound[],
247
- );
248
- },
249
- });
250
- }
251
- }
252
- };
253
-
254
- type SectionToUpdate = {
255
- identifier: Identifier | MemberExpression;
256
- newCode: string;
257
- startIndex: number;
258
- endIndex: number;
259
- };
260
-
261
- const convertPropUsage = (
262
- propUsage: ValidPropsFound,
263
- sourceCode: SourceCode,
264
- ): string | undefined => {
265
- const arrowFunctionOffset = propUsage.arrowFunctionExpression.body.loc
266
- ? {
267
- startIndex: sourceCode.getIndexFromLoc(propUsage.arrowFunctionExpression.body.loc.start),
268
- endIndex: sourceCode.getIndexFromLoc(propUsage.arrowFunctionExpression.body.loc.end),
269
- }
270
- : undefined;
271
-
272
- if (!arrowFunctionOffset) {
273
- return;
274
- }
275
-
276
- const sectionsToUpdate: SectionToUpdate[] = [];
277
- const newCode: string[] = [];
278
-
279
- for (const prop of propUsage.props) {
280
- for (const usage of prop.usages) {
281
- if (!usage.loc) {
282
- return;
283
- }
284
-
285
- sectionsToUpdate.push({
286
- identifier: usage,
287
- newCode: prop.propName,
288
- startIndex: sourceCode.getIndexFromLoc(usage.loc.start),
289
- endIndex: sourceCode.getIndexFromLoc(usage.loc.end),
290
- });
291
- }
292
- }
293
-
294
- sectionsToUpdate.sort((a, b) => {
295
- if (!a.identifier.loc || !b.identifier.loc) {
296
- return 0;
297
- }
298
- return (
299
- a.identifier.loc.start.line - b.identifier.loc.start.line ||
300
- a.identifier.loc.start.column - b.identifier.loc.start.column
301
- );
302
- });
303
-
304
- let prevEndIndex = arrowFunctionOffset.startIndex;
305
- for (const section of sectionsToUpdate) {
306
- if (prevEndIndex > section.startIndex || prevEndIndex >= section.endIndex) {
307
- // Props overlap! This is unexpected, bail out.
308
- return;
309
- }
310
-
311
- newCode.push(sourceCode.getText().slice(prevEndIndex, section.startIndex));
312
- newCode.push(section.newCode);
313
-
314
- prevEndIndex = section.endIndex;
315
- }
316
-
317
- newCode.push(sourceCode.getText().slice(prevEndIndex, arrowFunctionOffset.endIndex));
318
-
319
- return newCode.join('');
320
- };
321
-
322
- const fixPropsObjectUsages = (
323
- fixer: Rule.RuleFixer,
324
- sourceCode: SourceCode,
325
- expression: ObjectExpression,
326
- allProps: ValidPropsFound[],
327
- ): Rule.Fix[] => {
328
- const fixers = [
329
- // Wrap the object (containing the CSS properties and values) in an arrow function,
330
- // so it becomes something like
331
- //
332
- // styled.div(
333
- // (props) => ({
334
- // color: ...
335
- // })
336
- // );
337
- fixer.insertTextBefore(expression, '(props) => ('),
338
- fixer.insertTextAfter(expression, ')'),
339
- ];
340
-
341
- for (const propUsage of allProps) {
342
- const arrowFunctionExpression = propUsage.arrowFunctionExpression;
343
- const newCode = convertPropUsage(propUsage, sourceCode);
344
-
345
- if (newCode) {
346
- fixers.push(fixer.replaceText(arrowFunctionExpression, newCode));
347
- }
348
- }
349
-
350
- return fixers;
351
- };
352
-
353
- export const rule = createLintRule({
354
- meta: {
355
- name: 'convert-props-syntax',
356
- docs: {
357
- description:
358
- 'Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries.',
359
- recommended: true,
360
- severity: 'error',
361
- },
362
- fixable: 'code',
363
- messages: {
364
- 'unsupported-prop-syntax':
365
- 'This syntax is not supported by styled-components@<4 or @emotion/styled and will fail at runtime!\n\nTo fix this, you can either migrate this to `@compiled/react`, or use the autofixer to switch the syntax from the `styled.div({ property: (props) => props.value })` syntax to the `styled.div(props => ({ property: props.value }))` syntax.',
366
-
367
- 'unsupported-prop-syntax-no-autofixer':
368
- 'This syntax is not supported by styled-components@<4 or @emotion/styled and will fail at runtime!\n\nTo fix this, you can either migrate this to `@compiled/react`, or manually migrate the syntax from the `styled.div({ property: (props) => props.value })` syntax to the `styled.div(props => ({ property: props.value }))` syntax.\n\nCheck out the rule documentation for examples.',
369
- },
370
- type: 'problem',
371
- },
372
- create(context) {
373
- return {
374
- CallExpression: (node: CallExpression) => {
375
- const references = context.getScope().references;
376
-
377
- // Rule should ignore .attrs() calls
378
- if (
379
- node.callee.type === 'MemberExpression' &&
380
- node.callee.property.type === 'Identifier' &&
381
- node.callee.property.name === 'attrs'
382
- ) {
383
- return;
384
- }
385
-
386
- const callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
387
-
388
- if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
389
- return;
390
- }
391
-
392
- /**
393
- * We only want to lint the second set of arguments in the following cases:
394
- *
395
- * 1. styled(BaseComponent)({ ... })
396
- * 2. styled(BaseComponent)``
397
- */
398
- if (
399
- // Using this type assertion to cast into a more useful type
400
- // For some reason the estree types are missing useful things like `parent`
401
- isNodeOfType(node, 'CallExpression') &&
402
- (node.parent?.type === 'CallExpression' ||
403
- node.parent?.type === 'TaggedTemplateExpression')
404
- ) {
405
- return;
406
- }
407
-
408
- lintArguments(context, node.arguments);
409
- },
410
- };
411
- },
412
- });
413
-
414
- export default rule;
@@ -1,45 +0,0 @@
1
- Blocks providing static values through the `style` prop, which should only be used to provide
2
- dynamic values (values unknown at build time).
3
-
4
- Use the `css` prop for providing static values instead.
5
-
6
- ## Examples
7
-
8
- ### Incorrect
9
-
10
- ```tsx
11
- import { token } from '@atlaskit/tokens';
12
-
13
- const Component = () => (
14
- <div
15
- style={{
16
- margin: 0,
17
- color: token('color.text.danger'),
18
- }}
19
- />
20
- );
21
- ```
22
-
23
- ### Correct
24
-
25
- Although `token` is a function call, it is statically resolvable by Compiled and should not be used
26
- in the `style` prop.
27
-
28
- ```tsx
29
- import { css } from '@compiled/react';
30
- import { token } from '@atlaskit/tokens';
31
-
32
- type Props = { width: string };
33
-
34
- const baseStyles = css({ margin: 0, color: token('color.text.danger') });
35
-
36
- const Component = ({ width }: Props) => (
37
- <div
38
- css={baseStyles}
39
- style={{
40
- width: props.width,
41
- '--my-nested-width': props.width,
42
- }}
43
- />
44
- );
45
- ```