@atlaskit/eslint-plugin-ui-styling-standard 0.17.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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/presets/all.codegen.js +3 -2
- package/dist/cjs/presets/recommended.codegen.js +3 -2
- package/dist/cjs/rules/external-rules.js +3 -1
- package/dist/es2019/presets/all.codegen.js +3 -2
- package/dist/es2019/presets/recommended.codegen.js +3 -2
- package/dist/es2019/rules/external-rules.js +3 -1
- package/dist/esm/presets/all.codegen.js +3 -2
- package/dist/esm/presets/recommended.codegen.js +3 -2
- package/dist/esm/rules/external-rules.js +3 -1
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/package.json +2 -2
- package/afm-cc/tsconfig.json +0 -28
- package/afm-jira/tsconfig.json +0 -28
- package/build/tsconfig.json +0 -18
- package/constellation/atlaskit-theme/usage.mdx +0 -132
- package/constellation/consistent-css-prop-usage/usage.mdx +0 -7
- package/constellation/convert-props-syntax/usage.mdx +0 -130
- package/constellation/enforce-style-prop/usage.mdx +0 -47
- package/constellation/index/migration-guide.mdx +0 -309
- package/constellation/index/overview.mdx +0 -250
- package/constellation/index/props.mdx +0 -30
- package/constellation/local-cx-xcss/usage.mdx +0 -53
- package/constellation/no-array-arguments/usage.mdx +0 -49
- package/constellation/no-classname-prop/usage.mdx +0 -49
- package/constellation/no-container-queries/usage.mdx +0 -101
- package/constellation/no-css-tagged-template-expression/usage.mdx +0 -8
- package/constellation/no-dynamic-styles/usage.mdx +0 -130
- package/constellation/no-empty-styled-expression/usage.mdx +0 -8
- package/constellation/no-exported-css/usage.mdx +0 -8
- package/constellation/no-exported-keyframes/usage.mdx +0 -8
- package/constellation/no-exported-styles/usage.mdx +0 -87
- package/constellation/no-global-styles/usage.mdx +0 -60
- package/constellation/no-important-styles/usage.mdx +0 -33
- package/constellation/no-imported-style-values/usage.mdx +0 -157
- package/constellation/no-invalid-css-map/usage.mdx +0 -8
- package/constellation/no-js-xcss/usage.mdx +0 -7
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -8
- package/constellation/no-nested-selectors/usage.mdx +0 -95
- package/constellation/no-styled/usage.mdx +0 -92
- package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -8
- package/constellation/no-suppress-xcss/usage.mdx +0 -28
- package/constellation/no-unsafe-selectors/usage.mdx +0 -370
- package/constellation/no-unsafe-values/usage.mdx +0 -318
- package/constellation/use-compiled/usage.mdx +0 -54
- package/index.js +0 -24
- package/scripts/codegen.tsx +0 -373
- package/src/index.codegen.tsx +0 -14
- package/src/index.tsx +0 -1
- package/src/presets/all.codegen.tsx +0 -79
- package/src/presets/recommended.codegen.tsx +0 -79
- package/src/rules/TEMPLATE.md +0 -29
- package/src/rules/__tests__/utils/_tester.tsx +0 -40
- package/src/rules/atlaskit-theme/README.md +0 -130
- package/src/rules/atlaskit-theme/__tests__/test.ts +0 -133
- package/src/rules/atlaskit-theme/index.ts +0 -134
- package/src/rules/convert-props-syntax/README.md +0 -128
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +0 -76
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +0 -584
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +0 -140
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +0 -69
- package/src/rules/convert-props-syntax/index.tsx +0 -414
- package/src/rules/enforce-style-prop/README.md +0 -45
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +0 -243
- package/src/rules/enforce-style-prop/index.tsx +0 -172
- package/src/rules/external-rules.tsx +0 -175
- package/src/rules/index.codegen.tsx +0 -42
- package/src/rules/local-cx-xcss/README.md +0 -51
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +0 -102
- package/src/rules/local-cx-xcss/index.tsx +0 -62
- package/src/rules/no-array-arguments/README.md +0 -47
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +0 -107
- package/src/rules/no-array-arguments/index.tsx +0 -86
- package/src/rules/no-classname-prop/README.md +0 -47
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +0 -39
- package/src/rules/no-classname-prop/index.tsx +0 -34
- package/src/rules/no-container-queries/README.md +0 -99
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +0 -139
- package/src/rules/no-container-queries/index.tsx +0 -94
- package/src/rules/no-dynamic-styles/README.md +0 -128
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +0 -135
- package/src/rules/no-dynamic-styles/index.tsx +0 -60
- package/src/rules/no-exported-styles/README.md +0 -85
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +0 -216
- package/src/rules/no-exported-styles/index.tsx +0 -52
- package/src/rules/no-global-styles/README.md +0 -58
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +0 -33
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +0 -46
- package/src/rules/no-global-styles/index.tsx +0 -82
- package/src/rules/no-important-styles/README.md +0 -31
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +0 -165
- package/src/rules/no-important-styles/index.tsx +0 -70
- package/src/rules/no-imported-style-values/README.md +0 -155
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +0 -491
- package/src/rules/no-imported-style-values/index.tsx +0 -188
- package/src/rules/no-nested-selectors/README.md +0 -93
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +0 -335
- package/src/rules/no-nested-selectors/index.tsx +0 -99
- package/src/rules/no-styled/README.md +0 -90
- package/src/rules/no-styled/__tests__/rule.test.tsx +0 -73
- package/src/rules/no-styled/index.tsx +0 -45
- package/src/rules/no-unsafe-selectors/README.md +0 -368
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +0 -368
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +0 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +0 -73
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +0 -40
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +0 -101
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +0 -131
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +0 -132
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +0 -25
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +0 -35
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +0 -257
- package/src/rules/no-unsafe-selectors/constants.tsx +0 -91
- package/src/rules/no-unsafe-selectors/index.tsx +0 -198
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +0 -155
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +0 -55
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +0 -226
- package/src/rules/no-unsafe-values/README.md +0 -316
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +0 -27
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +0 -37
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +0 -229
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +0 -267
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +0 -52
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +0 -106
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +0 -44
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +0 -48
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +0 -75
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +0 -121
- package/src/rules/no-unsafe-values/index.tsx +0 -94
- package/src/rules/no-unsafe-values/messages.tsx +0 -86
- package/src/rules/no-unsafe-values/utils.tsx +0 -387
- package/src/rules/use-compiled/README.md +0 -52
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +0 -73
- package/src/rules/use-compiled/__tests__/css.test.tsx +0 -126
- package/src/rules/use-compiled/__tests__/imports.test.tsx +0 -158
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +0 -140
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +0 -108
- package/src/rules/use-compiled/__tests__/styled.test.tsx +0 -114
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +0 -15
- package/src/rules/use-compiled/index.tsx +0 -252
- package/src/rules/use-compiled/is-safe.tsx +0 -159
- package/src/rules/use-compiled/utils.tsx +0 -33
- package/src/rules/utils/create-rule-with-typed-config.tsx +0 -86
- package/src/rules/utils/create-rule.tsx +0 -13
- package/tsconfig.app.json +0 -47
- package/tsconfig.dev.json +0 -45
- 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
|
-
);
|