@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.
- package/CHANGELOG.md +17 -0
- package/README.md +11 -7
- package/constellation/atlaskit-theme/usage.mdx +113 -0
- package/constellation/convert-props-syntax/usage.mdx +32 -22
- package/constellation/enforce-style-prop/usage.mdx +21 -18
- package/constellation/index/overview.mdx +92 -76
- package/constellation/local-cx-xcss/usage.mdx +10 -6
- package/constellation/no-array-arguments/usage.mdx +10 -9
- package/constellation/no-classname-prop/usage.mdx +7 -4
- package/constellation/no-container-queries/usage.mdx +17 -15
- package/constellation/no-dynamic-styles/usage.mdx +26 -29
- package/constellation/no-exported-styles/usage.mdx +23 -18
- package/constellation/no-important-styles/usage.mdx +5 -3
- package/constellation/no-imported-style-values/usage.mdx +30 -22
- package/constellation/no-nested-selectors/usage.mdx +22 -20
- package/constellation/no-unsafe-values/usage.mdx +45 -51
- package/constellation/use-compiled/usage.mdx +51 -0
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
- package/dist/cjs/rules/index.codegen.js +6 -2
- package/dist/cjs/rules/use-compiled/index.js +257 -0
- package/dist/cjs/rules/use-compiled/is-safe.js +130 -0
- package/dist/cjs/rules/use-compiled/utils.js +26 -0
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/atlaskit-theme/index.js +85 -0
- package/dist/es2019/rules/index.codegen.js +6 -2
- package/dist/es2019/rules/use-compiled/index.js +182 -0
- package/dist/es2019/rules/use-compiled/is-safe.js +118 -0
- package/dist/es2019/rules/use-compiled/utils.js +15 -0
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/atlaskit-theme/index.js +89 -0
- package/dist/esm/rules/index.codegen.js +6 -2
- package/dist/esm/rules/use-compiled/index.js +250 -0
- package/dist/esm/rules/use-compiled/is-safe.js +121 -0
- package/dist/esm/rules/use-compiled/utils.js +17 -0
- package/dist/types/index.codegen.d.ts +4 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/presets/recommended.codegen.d.ts +3 -1
- package/dist/types/rules/atlaskit-theme/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/use-compiled/index.d.ts +3 -0
- package/dist/types/rules/use-compiled/is-safe.d.ts +10 -0
- package/dist/types/rules/use-compiled/utils.d.ts +6 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe.d.ts +10 -0
- package/dist/types-ts4.5/rules/use-compiled/utils.d.ts +6 -0
- package/package.json +3 -2
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +67 -69
- package/src/presets/recommended.codegen.tsx +67 -69
- package/src/rules/atlaskit-theme/README.md +109 -0
- package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
- package/src/rules/atlaskit-theme/index.ts +136 -0
- package/src/rules/index.codegen.tsx +17 -13
- package/src/rules/use-compiled/README.md +49 -0
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +73 -0
- package/src/rules/use-compiled/__tests__/css.test.tsx +126 -0
- package/src/rules/use-compiled/__tests__/imports.test.tsx +139 -0
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +140 -0
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +108 -0
- package/src/rules/use-compiled/__tests__/styled.test.tsx +114 -0
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +15 -0
- package/src/rules/use-compiled/index.tsx +275 -0
- package/src/rules/use-compiled/is-safe.tsx +163 -0
- 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::
|
|
3
|
+
* @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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::
|
|
3
|
+
* @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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;
|