@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,130 +0,0 @@
1
- Blocks legacy `@atlaskit/theme` mixins that `@compiled/react` cannot compile. This includes the
2
- `typography`, `elevation` and `skeletonShimmer` mixins.
3
-
4
- ## Examples
5
-
6
- ### Typography
7
-
8
- Don't use `typography` mixins.
9
-
10
- Use [typography tokens](https://atlassian.design/foundations/typography-beta/applying-typography) or
11
- the [Heading](https://atlassian.design/components/heading) and
12
- [Text](https://atlassian.design/components/primitives/text) components.
13
-
14
- #### Incorrect
15
-
16
- ```tsx
17
- import { css } from '@compiled/react';
18
- import { typography } from '@atlaskit/theme';
19
-
20
- const titleStyles = css(typography.h700());
21
- ```
22
-
23
- #### Correct
24
-
25
- ```tsx
26
- import { css } from '@compiled/react';
27
- import { token } from '@atlaskit/tokens';
28
-
29
- const titleStyles = css({
30
- font: token('font.heading.large'),
31
- });
32
-
33
- const paragraphStyles = css({
34
- font: token('font.body.large'),
35
- });
36
- ```
37
-
38
- ```tsx
39
- import { css } from '@compiled/react';
40
- import Heading from '@atlaskit/heading';
41
- import { Stack, Text } from '@atlaskit/primitives';
42
- import { token } from '@atlaskit/tokens';
43
-
44
- const Component = () => (
45
- <Stack>
46
- <Heading size="large">Title</Heading>
47
- <Text size="large">Lorem ipsum</Text>
48
- </Stack>
49
- );
50
- ```
51
-
52
- ### Elevation
53
-
54
- Don't use `elevation` mixins.
55
-
56
- Use [elevation tokens](https://atlassian.design/foundations/elevation) instead.
57
-
58
- #### Incorrect
59
-
60
- ```tsx
61
- import { css } from '@compiled/react';
62
- import { elevation } from '@atlaskit/theme';
63
-
64
- const cardStyles = css(elevation.e100());
65
- ```
66
-
67
- #### Correct
68
-
69
- ```tsx
70
- import { styled } from '@compiled/react';
71
- import { token } from '@atlaskit/tokens';
72
-
73
- const cardStyles = css({
74
- backgroundColor: token('elevation.surface.raised'),
75
- boxShadow: token('elevation.shadow.raised'),
76
- });
77
- ```
78
-
79
- ### Skeleton Shimmer
80
-
81
- Don't use the `skeletonShimmer` mixin.
82
-
83
- Preview our [Skeleton](https://staging.atlassian.design/components/skeleton/examples) component
84
- (internal Atlassians only).
85
-
86
- Otherwise:
87
-
88
- - Use the `color.skeleton` and `color.skeleton.subtle` tokens to make your own component.
89
- - Use `@atlassian/jira-skeletons` when working on Jira (internal Atlassians only).
90
-
91
- #### Incorrect
92
-
93
- ```tsx
94
- import { css } from '@compiled/react';
95
- import { skeletonShimmer } from '@atlaskit/theme/constants';
96
-
97
- const skeletonStyles = css(skeletonShimmer());
98
- ```
99
-
100
- #### Correct
101
-
102
- ```tsx
103
- import Skeleton from '@atlaskit/skeleton';
104
-
105
- <Skeleton width="200px" height="16px" isShimmering />;
106
- ```
107
-
108
- ```tsx
109
- import { css, keyframes } from '@compiled/react';
110
-
111
- const shimmer = keyframes({
112
- from: { backgroundColor: token('color.skeleton') },
113
- to: { backgroundColor: token('color.skeleton.subtle') },
114
- });
115
-
116
- const skeletonStyles = css({
117
- backgroundColor: token('color.skeleton'),
118
- animationName: shimmer,
119
- animationDuration: '1.5s',
120
- animationIterationCount: 'infinite',
121
- animationTimingFunction: 'linear',
122
- animationDirection: 'alternate',
123
- });
124
- ```
125
-
126
- ```tsx
127
- import { ListSkeleton } from '@atlassian/jira-skeletons';
128
-
129
- <ListSkeleton numOfRows={3} />;
130
- ```
@@ -1,133 +0,0 @@
1
- import outdent from 'outdent';
2
- import { typescriptEslintTester } from '../../__tests__/utils/_tester';
3
- import rule from '../index';
4
-
5
- const valid = [
6
- {
7
- name: 'Valid typography use in styled-components',
8
- code: outdent`
9
- import styled from 'styled-components';
10
- import { typography } from '@atlaskit/theme';
11
- export const HeadingComponent = styled.h2\`
12
- \${typography.h200()};
13
- \`;
14
- `,
15
- },
16
- {
17
- name: 'Valid typography use in compiled (fontFallback)',
18
- code: outdent`
19
- import { styled } from '@compiled/react';
20
- import { fontFallback } from '@atlaskit/theme/typography';
21
- import { token } from '@atlaskit/tokens';
22
- export const HeadingComponent = styled.h2\`
23
- font: \${token('font.body', fontFallback.body.medium)}
24
- \`;
25
- `,
26
- },
27
- {
28
- name: 'Valid elevation use in styled-components',
29
- code: outdent`
30
- import styled from 'styled-components';
31
- import { elevation } from '@atlaskit/theme';
32
- export const HeadingComponent = styled.h2\`
33
- \${elevation.e100};
34
- \`;
35
- `,
36
- },
37
- {
38
- name: 'Valid skeleton shimmer use in styled-components',
39
- code: outdent`
40
- import styled from 'styled-components';
41
- import { skeletonShimmer } from '@atlaskit/theme/constants';
42
-
43
- export const SkeletonShimmerComponent = styled.div\`
44
- \${skeletonShimmer};
45
- \`
46
- `,
47
- },
48
- ];
49
-
50
- const typography = [
51
- {
52
- name: 'Invalid typography use in compiled with template expression',
53
- code: outdent`
54
- import { styled } from '@compiled/react';
55
- import { typography } from '@atlaskit/theme';
56
-
57
- export const HeadingComponent = styled.h2\`
58
- \${typography.h200()};
59
- \`;
60
- `,
61
- errors: [{ messageId: 'usingTypography' }],
62
- },
63
- {
64
- name: 'Invalid typography use in compiled with function call',
65
- code: outdent`
66
- import { styled } from '@compiled/react';
67
- import { typography } from '@atlaskit/theme';
68
-
69
- export const HeadingComponent = styled.h2(typography.h200());
70
- `,
71
- errors: [{ messageId: 'usingTypography' }],
72
- },
73
- ];
74
-
75
- const elevation = [
76
- {
77
- name: 'Invalid elevation use in compiled with template expression',
78
- code: outdent`
79
- import { styled } from '@compiled/react';
80
- import { elevation } from '@atlaskit/theme';
81
-
82
- export const ElevationComponent = styled.div\`
83
- \${elevation.e100()};
84
- \`;
85
- `,
86
- errors: [{ messageId: 'usingElevation' }],
87
- },
88
- {
89
- name: 'Invalid elevation use in compiled with function call',
90
- code: outdent`
91
- import { styled } from '@compiled/react';
92
- import { elevation } from '@atlaskit/theme';
93
-
94
- export const ElevationComponent = styled.div(elevation.e100());
95
- `,
96
- errors: [{ messageId: 'usingElevation' }],
97
- },
98
- ];
99
-
100
- const skeletonShimmer = [
101
- {
102
- name: 'Invalid skeleton shimmer use in compiled with template expression',
103
- code: outdent`
104
- import { styled } from '@compiled/react';
105
- import { skeletonShimmer } from '@atlaskit/theme/constants';
106
-
107
- export const SkeletonShimmerComponent = styled.div\`
108
- \${skeletonShimmer};
109
- \`;
110
- `,
111
- errors: [{ messageId: 'usingSkeletonShimmer' }],
112
- },
113
- {
114
- name: 'Invalid skeleton shimmer use in compiled with function call',
115
- code: outdent`
116
- import { styled } from '@compiled/react';
117
- import { skeletonShimmer } from '@atlaskit/theme/constants';
118
-
119
- export const SkeletonShimmerComponent = styled.div(skeletonShimmer);
120
- `,
121
- errors: [{ messageId: 'usingSkeletonShimmer' }],
122
- },
123
- ];
124
-
125
- typescriptEslintTester.run(
126
- 'atlaskit-theme',
127
- // @ts-expect-error
128
- rule,
129
- {
130
- valid,
131
- invalid: [...typography, ...elevation, ...skeletonShimmer],
132
- },
133
- );
@@ -1,134 +0,0 @@
1
- import type { Rule, Scope } from 'eslint';
2
-
3
- import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
4
- import { createLintRule } from '../utils/create-rule';
5
-
6
- const isIdentifierReferenced = (
7
- hasImportSpecifier: (def: Scope.Definition) => boolean,
8
- node: Rule.Node,
9
- references: Scope.Reference[],
10
- ): boolean =>
11
- references.some(
12
- (reference) =>
13
- reference.identifier === node && reference.resolved?.defs.some(hasImportSpecifier),
14
- );
15
-
16
- const isTypographyImportSpecifier = (def: Scope.Definition): boolean =>
17
- def.node.type === 'ImportSpecifier' &&
18
- def.node.imported.type === 'Identifier' &&
19
- def.parent?.type === 'ImportDeclaration' &&
20
- ((def.node.imported.name === 'typography' && def.parent?.source.value === '@atlaskit/theme') ||
21
- def.parent?.source.value === '@atlaskit/theme/typography');
22
-
23
- const isElevationImportSpecifier = (def: Scope.Definition): boolean =>
24
- def.node.type === 'ImportSpecifier' &&
25
- def.node.imported.type === 'Identifier' &&
26
- def.parent?.type === 'ImportDeclaration' &&
27
- ((def.node.imported.name === 'elevation' && def.parent?.source.value === '@atlaskit/theme') ||
28
- def.parent?.source.value === '@atlaskit/theme/elevation');
29
-
30
- const isSkeletonShimmerImportSpecifier = (def: Scope.Definition): boolean =>
31
- def.node.type === 'ImportSpecifier' &&
32
- def.node.imported.type === 'Identifier' &&
33
- def.parent?.type === 'ImportDeclaration' &&
34
- def.node.imported.name === 'skeletonShimmer' &&
35
- typeof def.parent?.source.value === 'string' &&
36
- def.parent?.source.value?.startsWith('@atlaskit/theme');
37
-
38
- const checkIdentifier = (
39
- node: Rule.Node,
40
- context: Rule.RuleContext,
41
- references: Scope.Reference[],
42
- ) => {
43
- if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
44
- context.report({
45
- messageId: 'usingTypography',
46
- node,
47
- });
48
- }
49
-
50
- if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
51
- context.report({
52
- messageId: 'usingElevation',
53
- node,
54
- });
55
- }
56
-
57
- if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
58
- context.report({
59
- messageId: 'usingSkeletonShimmer',
60
- node,
61
- });
62
- }
63
- };
64
-
65
- export const rule = createLintRule({
66
- meta: {
67
- name: 'atlaskit-theme',
68
- docs: {
69
- description:
70
- 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
71
- recommended: true,
72
- severity: 'error',
73
- },
74
- messages: {
75
- usingTypography:
76
- 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
77
- usingElevation:
78
- 'Elevation does not work with Compiled. Please use a token with a fallback instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
79
- usingSkeletonShimmer:
80
- 'Skeleton Shimmer does not work with Compiled. Please use an SVG skeleton instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
81
- },
82
- schema: [],
83
- type: 'problem',
84
- },
85
- create(context) {
86
- const importSources = getImportSources(context);
87
-
88
- return {
89
- 'CallExpression Identifier': (node: Rule.Node): void => {
90
- const { references } = context.getScope();
91
- const ancestors = context.getAncestors();
92
-
93
- // Check if ancestor node is a call expression to Compiled
94
- if (
95
- ancestors.some(
96
- (ancestor) =>
97
- ancestor.type === 'CallExpression' &&
98
- ancestor.callee &&
99
- isCompiled(ancestor.callee, references, importSources),
100
- )
101
- ) {
102
- // Ignore the fontFallback object as it contains strings to be used as token fallbacks
103
- if ('name' in node && node.name !== 'fontFallback') {
104
- // Check identifier for violations
105
- checkIdentifier(node, context, references);
106
- }
107
- }
108
- },
109
-
110
- 'TaggedTemplateExpression Identifier': (node: Rule.Node): void => {
111
- const { references } = context.getScope();
112
- const ancestors = context.getAncestors();
113
-
114
- // Check if ancestor node is a tagged template expression to Compiled
115
- if (
116
- ancestors.some(
117
- (ancestor) =>
118
- ancestor.type === 'TaggedTemplateExpression' &&
119
- ancestor.tag &&
120
- isCompiled(ancestor.tag, references, importSources),
121
- )
122
- ) {
123
- // Ignore the fontFallback object as it contains strings to be used as token fallbacks
124
- if ('name' in node && node.name !== 'fontFallback') {
125
- // Check identifier for violations
126
- checkIdentifier(node, context, references);
127
- }
128
- }
129
- },
130
- };
131
- },
132
- });
133
-
134
- export default rule;
@@ -1,128 +0,0 @@
1
- Blocks dynamic styling syntax that is unsupported by `styled-components@<4` and `@emotion/styled`,
2
- and provides an autofix for converting to a supported syntax.
3
-
4
- Use this rule alongside `no-styled-tagged-template-expression`, which can output the unsupported
5
- dynamic styling syntax.
6
-
7
- This rule applies only to `styled` usages from `styled-components` and `@emotion/styled`.
8
-
9
- ## Autofix
10
-
11
- The autofix will find style object values that are arrow functions,
12
-
13
- ```tsx
14
- styled.div({
15
- color: ({ myColor }) => myColor,
16
- backgroundColor: (props) => props.someColor,
17
- });
18
- ```
19
-
20
- However, refactoring the arrow function so that it is the argument to `styled.div` will fix the
21
- issue:
22
-
23
- ```tsx
24
- styled.div((props) => ({
25
- color: props.myColor,
26
- backgroundColor: props.someColor,
27
- }));
28
- ```
29
-
30
- This ESLint rule will only run on usages of the `styled` API when imported from libraries that are
31
- known to have this problem.
32
-
33
- ## About the autofixer
34
-
35
- This rule has an autofixer that will automatically perform the above arrow function refactoring for
36
- the majority of cases, including for nested selectors and any props used in template literal values.
37
-
38
- However, there are a few situations where the autofixer will not be run. For these, you will need to
39
- manually fix the output, or migrate the code to `@compiled/react`.
40
-
41
- ### Type annotations
42
-
43
- Type annotations in the arrow function are not supported; you will need to remediate the lint error
44
- manually. For example:
45
-
46
- ```tsx
47
- type Props = {
48
- myColor: string;
49
- someColor: string;
50
- };
51
-
52
- styled.div({
53
- color: ({ myColor }: Props) => myColor,
54
- backgroundColor: (props: Props) => props.someColor,
55
- });
56
- ```
57
-
58
- could be refactored as
59
-
60
- ```tsx
61
- type Props = {
62
- myColor: string;
63
- someColor: string;
64
- };
65
-
66
- styled.div((props: Props) => ({
67
- color: props.myColor,
68
- backgroundColor: props.someColor,
69
- }));
70
- ```
71
-
72
- ### Special syntax in function parameters
73
-
74
- Rest elements, default values, and so on in the parameter of an arrow function will need to be
75
- remediated manually. For example:
76
-
77
- ```tsx
78
- styled.div({
79
- color: ({ myColor = '#fff' }) => myColor,
80
- backgroundColor: ({ myColor = '#aaa' }) => myColor,
81
- });
82
- ```
83
-
84
- could be refactored as
85
-
86
- ```tsx
87
- styled.div((props) => ({
88
- color: myColor ?? '#fff',
89
- backgroundColor: myColor ?? '#aaa',
90
- }));
91
- ```
92
-
93
- ## Examples
94
-
95
- ### Incorrect
96
-
97
- ```tsx
98
- import styled from 'styled-components';
99
-
100
- styled.div({
101
- color: ({ myColor }) => myColor,
102
- backgroundColor: (props) => props.someColor,
103
- });
104
-
105
- styled.div({
106
- color: `url(/tmp/${({ coolProp }) => coolProp}.png)`,
107
- });
108
- ```
109
-
110
- ### Correct
111
-
112
- ```tsx
113
- import styled from '@emotion/styled';
114
-
115
- styled.div((props) => ({
116
- color: props.myColor,
117
- backgroundColor: props.someColor,
118
- }));
119
-
120
- styled.div((props) => ({
121
- color: url(`/tmp/${coolProp}.png`),
122
- }));
123
- ```
124
-
125
- ## When not to use it
126
-
127
- You do not need this rule if you are not using a codebase that has a violating library as it will
128
- never do anything.
@@ -1,76 +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
- // ESLint rule shouldn't try to fix all of the test cases below, which are
12
- // erroneous and invalid. But we should still report an error nonetheless.
13
-
14
- {
15
- name: 'disables autofixer when two arguments in arrow function (with destructured props)',
16
- code: `
17
- import styled from 'styled-components';
18
-
19
- styled.div({
20
- color: ({ customColor }, anotherVariable) => customColor,
21
- });
22
- `,
23
- errors: [
24
- {
25
- messageId: 'unsupported-prop-syntax-no-autofixer',
26
- },
27
- ],
28
- },
29
- {
30
- name: 'disables autofixer when two arguments in arrow function (with props argument)',
31
- code: `
32
- import styled from 'styled-components';
33
-
34
- styled.div({
35
- color: (oneVariable, anotherVariable) => oneVariable.color,
36
- });
37
- `,
38
- errors: [
39
- {
40
- messageId: 'unsupported-prop-syntax-no-autofixer',
41
- },
42
- ],
43
- },
44
- {
45
- name: "disables autofixer when props argument doesn't match",
46
- code: `
47
- import styled from 'styled-components';
48
-
49
- styled.div({
50
- backgroundColor: (props) => myProps.customColor,
51
- });
52
- `,
53
- errors: [
54
- {
55
- messageId: 'unsupported-prop-syntax-no-autofixer',
56
- },
57
- ],
58
- },
59
- {
60
- name: "disables autofixer when destructured props don't match",
61
- code: `
62
- import styled from 'styled-components';
63
-
64
- styled.div({
65
- backgroundColor: ({ customColor }) => otherColor,
66
- });
67
- `,
68
- errors: [
69
- {
70
- messageId: 'unsupported-prop-syntax-no-autofixer',
71
- },
72
- ],
73
- },
74
- ],
75
- },
76
- );