@atlaskit/eslint-plugin-ui-styling-standard 0.11.5 → 0.12.0

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 (76) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +11 -7
  3. package/constellation/atlaskit-theme/usage.mdx +113 -0
  4. package/constellation/convert-props-syntax/usage.mdx +32 -22
  5. package/constellation/enforce-style-prop/usage.mdx +21 -18
  6. package/constellation/index/overview.mdx +92 -76
  7. package/constellation/local-cx-xcss/usage.mdx +10 -6
  8. package/constellation/no-array-arguments/usage.mdx +10 -9
  9. package/constellation/no-classname-prop/usage.mdx +7 -4
  10. package/constellation/no-container-queries/usage.mdx +17 -15
  11. package/constellation/no-dynamic-styles/usage.mdx +26 -29
  12. package/constellation/no-exported-styles/usage.mdx +23 -18
  13. package/constellation/no-important-styles/usage.mdx +5 -3
  14. package/constellation/no-imported-style-values/usage.mdx +30 -22
  15. package/constellation/no-nested-selectors/usage.mdx +22 -20
  16. package/constellation/no-unsafe-values/usage.mdx +45 -51
  17. package/constellation/use-compiled/usage.mdx +51 -0
  18. package/dist/cjs/index.codegen.js +1 -1
  19. package/dist/cjs/presets/all.codegen.js +3 -1
  20. package/dist/cjs/presets/recommended.codegen.js +3 -1
  21. package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
  22. package/dist/cjs/rules/index.codegen.js +6 -2
  23. package/dist/cjs/rules/use-compiled/index.js +257 -0
  24. package/dist/cjs/rules/use-compiled/is-safe.js +130 -0
  25. package/dist/cjs/rules/use-compiled/utils.js +26 -0
  26. package/dist/es2019/index.codegen.js +1 -1
  27. package/dist/es2019/presets/all.codegen.js +3 -1
  28. package/dist/es2019/presets/recommended.codegen.js +3 -1
  29. package/dist/es2019/rules/atlaskit-theme/index.js +85 -0
  30. package/dist/es2019/rules/index.codegen.js +6 -2
  31. package/dist/es2019/rules/use-compiled/index.js +182 -0
  32. package/dist/es2019/rules/use-compiled/is-safe.js +118 -0
  33. package/dist/es2019/rules/use-compiled/utils.js +15 -0
  34. package/dist/esm/index.codegen.js +1 -1
  35. package/dist/esm/presets/all.codegen.js +3 -1
  36. package/dist/esm/presets/recommended.codegen.js +3 -1
  37. package/dist/esm/rules/atlaskit-theme/index.js +89 -0
  38. package/dist/esm/rules/index.codegen.js +6 -2
  39. package/dist/esm/rules/use-compiled/index.js +250 -0
  40. package/dist/esm/rules/use-compiled/is-safe.js +121 -0
  41. package/dist/esm/rules/use-compiled/utils.js +17 -0
  42. package/dist/types/index.codegen.d.ts +4 -0
  43. package/dist/types/presets/all.codegen.d.ts +3 -1
  44. package/dist/types/presets/recommended.codegen.d.ts +3 -1
  45. package/dist/types/rules/atlaskit-theme/index.d.ts +3 -0
  46. package/dist/types/rules/index.codegen.d.ts +2 -0
  47. package/dist/types/rules/use-compiled/index.d.ts +3 -0
  48. package/dist/types/rules/use-compiled/is-safe.d.ts +10 -0
  49. package/dist/types/rules/use-compiled/utils.d.ts +6 -0
  50. package/dist/types-ts4.5/index.codegen.d.ts +4 -0
  51. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
  52. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
  53. package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +3 -0
  54. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  55. package/dist/types-ts4.5/rules/use-compiled/index.d.ts +3 -0
  56. package/dist/types-ts4.5/rules/use-compiled/is-safe.d.ts +10 -0
  57. package/dist/types-ts4.5/rules/use-compiled/utils.d.ts +6 -0
  58. package/package.json +3 -2
  59. package/src/index.codegen.tsx +3 -3
  60. package/src/presets/all.codegen.tsx +67 -69
  61. package/src/presets/recommended.codegen.tsx +67 -69
  62. package/src/rules/atlaskit-theme/README.md +109 -0
  63. package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
  64. package/src/rules/atlaskit-theme/index.ts +136 -0
  65. package/src/rules/index.codegen.tsx +17 -13
  66. package/src/rules/use-compiled/README.md +49 -0
  67. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +73 -0
  68. package/src/rules/use-compiled/__tests__/css.test.tsx +126 -0
  69. package/src/rules/use-compiled/__tests__/imports.test.tsx +139 -0
  70. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +140 -0
  71. package/src/rules/use-compiled/__tests__/pragma.test.tsx +108 -0
  72. package/src/rules/use-compiled/__tests__/styled.test.tsx +114 -0
  73. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +15 -0
  74. package/src/rules/use-compiled/index.tsx +275 -0
  75. package/src/rules/use-compiled/is-safe.tsx +163 -0
  76. package/src/rules/use-compiled/utils.tsx +37 -0
@@ -1,78 +1,76 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
3
+ * @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
7
- plugins: [
8
- '@atlaskit/ui-styling-standard',
9
- '@atlaskit/design-system',
10
- '@compiled',
11
- ],
12
- rules: {
13
- '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
- '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
15
- '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
16
- '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
17
- '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
18
- '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
19
- '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
20
- '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
21
- '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
22
- '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
23
- '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
24
- '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
25
- '@atlaskit/design-system/consistent-css-prop-usage': [
26
- 'warn',
27
- { excludeReactComponents: true },
28
- ],
29
- '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
30
- '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
31
- '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
32
- '@compiled/no-suppress-xcss': 'warn',
33
- '@compiled/no-js-xcss': 'warn',
34
- '@atlaskit/design-system/no-empty-styled-expression': [
35
- 'warn',
36
- {
37
- importSources: [
38
- '@compiled/react',
39
- '@atlaskit/css',
40
- '@emotion/core',
41
- '@emotion/react',
42
- '@emotion/styled',
43
- 'styled-components',
7
+ plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
8
+ rules: {
9
+ '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
10
+ '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
11
+ '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
12
+ '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
13
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
14
+ '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
15
+ '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
17
+ '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
18
+ '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
19
+ '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
20
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
21
+ '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
22
+ '@atlaskit/ui-styling-standard/use-compiled': 'warn',
23
+ '@atlaskit/design-system/consistent-css-prop-usage': [
24
+ 'warn',
25
+ { excludeReactComponents: true },
44
26
  ],
45
- },
46
- ],
47
- '@atlaskit/design-system/no-exported-css': [
48
- 'warn',
49
- {
50
- importSources: [
51
- '@compiled/react',
52
- '@atlaskit/css',
53
- '@emotion/core',
54
- '@emotion/react',
55
- '@emotion/styled',
56
- 'styled-components',
27
+ '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
28
+ '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
29
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
30
+ '@compiled/no-suppress-xcss': 'warn',
31
+ '@compiled/no-js-xcss': 'warn',
32
+ '@atlaskit/design-system/no-empty-styled-expression': [
33
+ 'warn',
34
+ {
35
+ importSources: [
36
+ '@compiled/react',
37
+ '@atlaskit/css',
38
+ '@emotion/core',
39
+ '@emotion/react',
40
+ '@emotion/styled',
41
+ 'styled-components',
42
+ ],
43
+ },
57
44
  ],
58
- },
59
- ],
60
- '@atlaskit/design-system/no-exported-keyframes': [
61
- 'warn',
62
- {
63
- importSources: [
64
- '@compiled/react',
65
- '@atlaskit/css',
66
- '@emotion/core',
67
- '@emotion/react',
68
- '@emotion/styled',
69
- 'styled-components',
45
+ '@atlaskit/design-system/no-exported-css': [
46
+ 'warn',
47
+ {
48
+ importSources: [
49
+ '@compiled/react',
50
+ '@atlaskit/css',
51
+ '@emotion/core',
52
+ '@emotion/react',
53
+ '@emotion/styled',
54
+ 'styled-components',
55
+ ],
56
+ },
70
57
  ],
71
- },
72
- ],
73
- '@atlaskit/design-system/no-invalid-css-map': [
74
- 'warn',
75
- { allowedFunctionCalls: [['@atlaskit/tokens', 'token']] },
76
- ],
77
- },
58
+ '@atlaskit/design-system/no-exported-keyframes': [
59
+ 'warn',
60
+ {
61
+ importSources: [
62
+ '@compiled/react',
63
+ '@atlaskit/css',
64
+ '@emotion/core',
65
+ '@emotion/react',
66
+ '@emotion/styled',
67
+ 'styled-components',
68
+ ],
69
+ },
70
+ ],
71
+ '@atlaskit/design-system/no-invalid-css-map': [
72
+ 'warn',
73
+ { allowedFunctionCalls: [['@atlaskit/tokens', 'token']] },
74
+ ],
75
+ },
78
76
  };
@@ -1,78 +1,76 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::96336e6094dbcbf456aaef313b624fbf>>
3
+ * @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
7
- plugins: [
8
- '@atlaskit/ui-styling-standard',
9
- '@atlaskit/design-system',
10
- '@compiled',
11
- ],
12
- rules: {
13
- '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
- '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
15
- '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
16
- '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
17
- '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
18
- '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
19
- '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
20
- '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
21
- '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
22
- '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
23
- '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
24
- '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
25
- '@atlaskit/design-system/consistent-css-prop-usage': [
26
- 'warn',
27
- { excludeReactComponents: true },
28
- ],
29
- '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
30
- '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
31
- '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
32
- '@compiled/no-suppress-xcss': 'warn',
33
- '@compiled/no-js-xcss': 'warn',
34
- '@atlaskit/design-system/no-empty-styled-expression': [
35
- 'warn',
36
- {
37
- importSources: [
38
- '@compiled/react',
39
- '@atlaskit/css',
40
- '@emotion/core',
41
- '@emotion/react',
42
- '@emotion/styled',
43
- 'styled-components',
7
+ plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
8
+ rules: {
9
+ '@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
10
+ '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
11
+ '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
12
+ '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
13
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
14
+ '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
15
+ '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
17
+ '@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
18
+ '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
19
+ '@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
20
+ '@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
21
+ '@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
22
+ '@atlaskit/ui-styling-standard/use-compiled': 'warn',
23
+ '@atlaskit/design-system/consistent-css-prop-usage': [
24
+ 'warn',
25
+ { excludeReactComponents: true },
44
26
  ],
45
- },
46
- ],
47
- '@atlaskit/design-system/no-exported-css': [
48
- 'warn',
49
- {
50
- importSources: [
51
- '@compiled/react',
52
- '@atlaskit/css',
53
- '@emotion/core',
54
- '@emotion/react',
55
- '@emotion/styled',
56
- 'styled-components',
27
+ '@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
28
+ '@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
29
+ '@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
30
+ '@compiled/no-suppress-xcss': 'warn',
31
+ '@compiled/no-js-xcss': 'warn',
32
+ '@atlaskit/design-system/no-empty-styled-expression': [
33
+ 'warn',
34
+ {
35
+ importSources: [
36
+ '@compiled/react',
37
+ '@atlaskit/css',
38
+ '@emotion/core',
39
+ '@emotion/react',
40
+ '@emotion/styled',
41
+ 'styled-components',
42
+ ],
43
+ },
57
44
  ],
58
- },
59
- ],
60
- '@atlaskit/design-system/no-exported-keyframes': [
61
- 'warn',
62
- {
63
- importSources: [
64
- '@compiled/react',
65
- '@atlaskit/css',
66
- '@emotion/core',
67
- '@emotion/react',
68
- '@emotion/styled',
69
- 'styled-components',
45
+ '@atlaskit/design-system/no-exported-css': [
46
+ 'warn',
47
+ {
48
+ importSources: [
49
+ '@compiled/react',
50
+ '@atlaskit/css',
51
+ '@emotion/core',
52
+ '@emotion/react',
53
+ '@emotion/styled',
54
+ 'styled-components',
55
+ ],
56
+ },
70
57
  ],
71
- },
72
- ],
73
- '@atlaskit/design-system/no-invalid-css-map': [
74
- 'warn',
75
- { allowedFunctionCalls: [['@atlaskit/tokens', 'token']] },
76
- ],
77
- },
58
+ '@atlaskit/design-system/no-exported-keyframes': [
59
+ 'warn',
60
+ {
61
+ importSources: [
62
+ '@compiled/react',
63
+ '@atlaskit/css',
64
+ '@emotion/core',
65
+ '@emotion/react',
66
+ '@emotion/styled',
67
+ 'styled-components',
68
+ ],
69
+ },
70
+ ],
71
+ '@atlaskit/design-system/no-invalid-css-map': [
72
+ 'warn',
73
+ { allowedFunctionCalls: [['@atlaskit/tokens', 'token']] },
74
+ ],
75
+ },
78
76
  };
@@ -0,0 +1,109 @@
1
+ This rule bans certain usages of `@atlaskit/theme` that `@compiled/react` is unable to compile. This includes `typography`, `elevation` and `skeletonShimmer`.
2
+
3
+ ## Examples
4
+
5
+ ### Typography
6
+
7
+ Use `<Heading>` instead of `typography`.
8
+
9
+ 👎 Example of **incorrect** code for this rule:
10
+
11
+ ```tsx
12
+ import { styled } from '@compiled/react';
13
+ import { typography } from '@atlaskit/theme';
14
+
15
+ export const HeadingComponent = styled.h2`
16
+ ${typography.h200()};
17
+ `;
18
+ ```
19
+
20
+ ```tsx
21
+ import { styled } from '@compiled/react';
22
+ import { typography } from '@atlaskit/theme';
23
+
24
+ export const HeadingComponent = styled.h2(typography.h200());
25
+ ```
26
+
27
+ 👍 Example of **correct** code for this rule:
28
+
29
+ ```tsx
30
+ import { styled } from '@compiled/react';
31
+
32
+ const HeadingComponent = styled.h2({
33
+ fontSize: '20px',
34
+ });
35
+ ```
36
+
37
+ ```tsx
38
+ import Heading from '@atlaskit/heading';
39
+ import { token } from '@atlaskit/tokens';
40
+ import { styled } from '@compiled/react';
41
+
42
+ const TitleComponent = styled.span({
43
+ marginTop: token('space.150', '12px'),
44
+ });
45
+
46
+ export const Title = (props) => (
47
+ <Heading level="h200" as="h3">
48
+ <TitleComponent {...props} />
49
+ </Heading>
50
+ );
51
+ ```
52
+
53
+ ### Elevation
54
+
55
+ We don’t support this mixin, please use tokens instead.
56
+
57
+ 👎 Example of **incorrect** code for this rule:
58
+
59
+ ```tsx
60
+ import { styled } from '@compiled/react';
61
+ import { elevation } from '@atlaskit/theme';
62
+
63
+ export const ElevationComponent = styled.div`
64
+ ${elevation.e100()};
65
+ `;
66
+ ```
67
+
68
+ 👍 Example of **correct** code for this rule:
69
+
70
+ ```tsx
71
+ import { styled } from '@compiled/react';
72
+ import { token } from '@atlaskit/tokens';
73
+
74
+ export const TestComponent = styled.div({
75
+ boxShadow: token(
76
+ 'elevation.shadow.raised',
77
+ '0 1px 1px rgba(9,30,66,0.25),0 0 1px 1px rgba(9,30,66,0.13)',
78
+ ),
79
+ });
80
+ ```
81
+
82
+ ### Skeleton Shimmer
83
+
84
+ You can preview our `@atlaskit/skeleton` (docs available to internal Atlassians only: [link](https://staging.atlassian.design/components/skeleton/examples)).
85
+
86
+ Otherwise, please use an SVG skeleton or your own `@compiled/react` variant yourself.
87
+
88
+ 👎 Example of **incorrect** code for this rule:
89
+
90
+ ```tsx
91
+ import { styled } from '@compiled/react';
92
+ import { skeletonShimmer } from '@atlaskit/theme/constants';
93
+
94
+ export const SkeletonShimmerComponent = styled.div`
95
+ ${skeletonShimmer};
96
+ `;
97
+ ```
98
+
99
+ 👍 Example of **correct** code for this rule:
100
+
101
+ ```tsx
102
+ export const SkeletonShimmerComponent = () => {
103
+ return (
104
+ <Wrapper>
105
+ <object data="./skeleton.svg" type="image/svg+xml"></object>
106
+ </Wrapper>
107
+ );
108
+ };
109
+ ```
@@ -0,0 +1,122 @@
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 elevation use in styled-components',
18
+ code: outdent`
19
+ import styled from 'styled-components';
20
+ import { elevation } from '@atlaskit/theme';
21
+ export const HeadingComponent = styled.h2\`
22
+ \${elevation.e100};
23
+ \`;
24
+ `,
25
+ },
26
+ {
27
+ name: 'Valid skeleton shimmer use in styled-components',
28
+ code: outdent`
29
+ import styled from 'styled-components';
30
+ import { skeletonShimmer } from '@atlaskit/theme/constants';
31
+
32
+ export const SkeletonShimmerComponent = styled.div\`
33
+ \${skeletonShimmer};
34
+ \`
35
+ `,
36
+ },
37
+ ];
38
+
39
+ const typography = [
40
+ {
41
+ name: 'Invalid typography use in compiled with template expression',
42
+ code: outdent`
43
+ import { styled } from '@compiled/react';
44
+ import { typography } from '@atlaskit/theme';
45
+
46
+ export const HeadingComponent = styled.h2\`
47
+ \${typography.h200()};
48
+ \`;
49
+ `,
50
+ errors: [{ messageId: 'usingTypography' }],
51
+ },
52
+ {
53
+ name: 'Invalid typography use in compiled with function call',
54
+ code: outdent`
55
+ import { styled } from '@compiled/react';
56
+ import { typography } from '@atlaskit/theme';
57
+
58
+ export const HeadingComponent = styled.h2(typography.h200());
59
+ `,
60
+ errors: [{ messageId: 'usingTypography' }],
61
+ },
62
+ ];
63
+
64
+ const elevation = [
65
+ {
66
+ name: 'Invalid elevation use in compiled with template expression',
67
+ code: outdent`
68
+ import { styled } from '@compiled/react';
69
+ import { elevation } from '@atlaskit/theme';
70
+
71
+ export const ElevationComponent = styled.div\`
72
+ \${elevation.e100()};
73
+ \`;
74
+ `,
75
+ errors: [{ messageId: 'usingElevation' }],
76
+ },
77
+ {
78
+ name: 'Invalid elevation use in compiled with function call',
79
+ code: outdent`
80
+ import { styled } from '@compiled/react';
81
+ import { elevation } from '@atlaskit/theme';
82
+
83
+ export const ElevationComponent = styled.div(elevation.e100());
84
+ `,
85
+ errors: [{ messageId: 'usingElevation' }],
86
+ },
87
+ ];
88
+
89
+ const skeletonShimmer = [
90
+ {
91
+ name: 'Invalid skeleton shimmer use in compiled with template expression',
92
+ code: outdent`
93
+ import { styled } from '@compiled/react';
94
+ import { skeletonShimmer } from '@atlaskit/theme/constants';
95
+
96
+ export const SkeletonShimmerComponent = styled.div\`
97
+ \${skeletonShimmer};
98
+ \`;
99
+ `,
100
+ errors: [{ messageId: 'usingSkeletonShimmer' }],
101
+ },
102
+ {
103
+ name: 'Invalid skeleton shimmer use in compiled with function call',
104
+ code: outdent`
105
+ import { styled } from '@compiled/react';
106
+ import { skeletonShimmer } from '@atlaskit/theme/constants';
107
+
108
+ export const SkeletonShimmerComponent = styled.div(skeletonShimmer);
109
+ `,
110
+ errors: [{ messageId: 'usingSkeletonShimmer' }],
111
+ },
112
+ ];
113
+
114
+ typescriptEslintTester.run(
115
+ 'atlaskit-theme',
116
+ // @ts-expect-error
117
+ rule,
118
+ {
119
+ valid,
120
+ invalid: [...typography, ...elevation, ...skeletonShimmer],
121
+ },
122
+ );
@@ -0,0 +1,136 @@
1
+ import type { Rule, Scope } from 'eslint';
2
+
3
+ import {
4
+ getImportSources,
5
+ isCompiled,
6
+ } from '@atlaskit/eslint-utils/is-supported-import';
7
+ import { createLintRule } from '../utils/create-rule';
8
+
9
+ const isIdentifierReferenced = (
10
+ hasImportSpecifier: (def: Scope.Definition) => boolean,
11
+ node: Rule.Node,
12
+ references: Scope.Reference[],
13
+ ): boolean =>
14
+ references.some(
15
+ (reference) =>
16
+ reference.identifier === node &&
17
+ reference.resolved?.defs.some(hasImportSpecifier),
18
+ );
19
+
20
+ const isTypographyImportSpecifier = (def: Scope.Definition): boolean =>
21
+ def.node.type === 'ImportSpecifier' &&
22
+ def.node.imported.type === 'Identifier' &&
23
+ def.parent?.type === 'ImportDeclaration' &&
24
+ ((def.node.imported.name === 'typography' &&
25
+ def.parent?.source.value === '@atlaskit/theme') ||
26
+ def.parent?.source.value === '@atlaskit/theme/typography');
27
+
28
+ const isElevationImportSpecifier = (def: Scope.Definition): boolean =>
29
+ def.node.type === 'ImportSpecifier' &&
30
+ def.node.imported.type === 'Identifier' &&
31
+ def.parent?.type === 'ImportDeclaration' &&
32
+ ((def.node.imported.name === 'elevation' &&
33
+ def.parent?.source.value === '@atlaskit/theme') ||
34
+ def.parent?.source.value === '@atlaskit/theme/elevation');
35
+
36
+ const isSkeletonShimmerImportSpecifier = (def: Scope.Definition): boolean =>
37
+ def.node.type === 'ImportSpecifier' &&
38
+ def.node.imported.type === 'Identifier' &&
39
+ def.parent?.type === 'ImportDeclaration' &&
40
+ def.node.imported.name === 'skeletonShimmer' &&
41
+ typeof def.parent?.source.value === 'string' &&
42
+ def.parent?.source.value?.startsWith('@atlaskit/theme');
43
+
44
+ const checkIdentifier = (
45
+ node: Rule.Node,
46
+ context: Rule.RuleContext,
47
+ references: Scope.Reference[],
48
+ ) => {
49
+ if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
50
+ context.report({
51
+ messageId: 'usingTypography',
52
+ node,
53
+ });
54
+ }
55
+
56
+ if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
57
+ context.report({
58
+ messageId: 'usingElevation',
59
+ node,
60
+ });
61
+ }
62
+
63
+ if (
64
+ isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)
65
+ ) {
66
+ context.report({
67
+ messageId: 'usingSkeletonShimmer',
68
+ node,
69
+ });
70
+ }
71
+ };
72
+
73
+ export const rule = createLintRule({
74
+ meta: {
75
+ name: 'atlaskit-theme',
76
+ docs: {
77
+ description:
78
+ 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
79
+ recommended: true,
80
+ severity: 'error',
81
+ },
82
+ messages: {
83
+ usingTypography:
84
+ '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',
85
+ usingElevation:
86
+ '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',
87
+ usingSkeletonShimmer:
88
+ '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',
89
+ },
90
+ schema: [],
91
+ type: 'problem',
92
+ },
93
+ create(context) {
94
+ const importSources = getImportSources(context);
95
+
96
+ return {
97
+ 'CallExpression Identifier': (node: Rule.Node): void => {
98
+ const { references } = context.getScope();
99
+ const ancestors = context.getAncestors();
100
+
101
+ // Check if ancestor node is a call expression to Compiled
102
+ if (
103
+ ancestors.some(
104
+ (ancestor) =>
105
+ ancestor.type === 'CallExpression' &&
106
+ ancestor.callee &&
107
+ isCompiled(ancestor.callee, references, importSources),
108
+ )
109
+ ) {
110
+ // Check identifier for violations
111
+ checkIdentifier(node, context, references);
112
+ }
113
+ },
114
+
115
+ 'TaggedTemplateExpression Identifier': (node: Rule.Node): void => {
116
+ const { references } = context.getScope();
117
+ const ancestors = context.getAncestors();
118
+
119
+ // Check if ancestor node is a tagged template expression to Compiled
120
+ if (
121
+ ancestors.some(
122
+ (ancestor) =>
123
+ ancestor.type === 'TaggedTemplateExpression' &&
124
+ ancestor.tag &&
125
+ isCompiled(ancestor.tag, references, importSources),
126
+ )
127
+ ) {
128
+ // Check identifier for violations
129
+ checkIdentifier(node, context, references);
130
+ }
131
+ },
132
+ };
133
+ },
134
+ });
135
+
136
+ export default rule;