@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.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 +17 -0
- package/constellation/consistent-css-prop-usage/usage.mdx +3 -1
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/constellation/no-css-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-empty-styled-expression/usage.mdx +5 -2
- package/constellation/no-exported-css/usage.mdx +5 -2
- package/constellation/no-exported-keyframes/usage.mdx +5 -2
- package/constellation/no-invalid-css-map/usage.mdx +5 -2
- package/constellation/no-js-xcss/usage.mdx +3 -1
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-suppress-xcss/usage.mdx +6 -3
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +141 -128
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +133 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
|
@@ -6,35 +6,35 @@ import { RuleTester } from 'eslint';
|
|
|
6
6
|
import __noop from '@atlaskit/ds-lib/noop';
|
|
7
7
|
|
|
8
8
|
(RuleTester as any).describe = (text: string, method: Function) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
const origHasAssertions = expect.hasAssertions;
|
|
10
|
+
describe(text, () => {
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
// Stub out expect.hasAssertions beforeEach from jest-presetup.js
|
|
13
|
+
expect.hasAssertions = __noop;
|
|
14
|
+
});
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
expect.hasAssertions = origHasAssertions;
|
|
17
|
+
});
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
method();
|
|
20
|
+
});
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const typescriptEslintTester = new ESLintUtils.RuleTester({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
parser: '@typescript-eslint/parser',
|
|
25
|
+
parserOptions: {
|
|
26
|
+
ecmaVersion: 2020,
|
|
27
|
+
sourceType: 'module',
|
|
28
|
+
ecmaFeatures: {
|
|
29
|
+
jsx: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
export const tester = new RuleTester({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
parser: require.resolve('@babel/eslint-parser'),
|
|
36
|
+
parserOptions: {
|
|
37
|
+
ecmaVersion: 6,
|
|
38
|
+
sourceType: 'module',
|
|
39
|
+
},
|
|
40
40
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
This rule bans certain usages of `@atlaskit/theme` that `@compiled/react` is unable to compile. This
|
|
1
|
+
This rule bans certain usages of `@atlaskit/theme` that `@compiled/react` is unable to compile. This
|
|
2
|
+
includes `typography`, `elevation` and `skeletonShimmer`.
|
|
2
3
|
|
|
3
4
|
## Examples
|
|
4
5
|
|
|
@@ -13,7 +14,7 @@ import { styled } from '@compiled/react';
|
|
|
13
14
|
import { typography } from '@atlaskit/theme';
|
|
14
15
|
|
|
15
16
|
export const HeadingComponent = styled.h2`
|
|
16
|
-
|
|
17
|
+
${typography.h200()};
|
|
17
18
|
`;
|
|
18
19
|
```
|
|
19
20
|
|
|
@@ -30,7 +31,7 @@ export const HeadingComponent = styled.h2(typography.h200());
|
|
|
30
31
|
import { styled } from '@compiled/react';
|
|
31
32
|
|
|
32
33
|
const HeadingComponent = styled.h2({
|
|
33
|
-
|
|
34
|
+
fontSize: '20px',
|
|
34
35
|
});
|
|
35
36
|
```
|
|
36
37
|
|
|
@@ -40,13 +41,13 @@ import { token } from '@atlaskit/tokens';
|
|
|
40
41
|
import { styled } from '@compiled/react';
|
|
41
42
|
|
|
42
43
|
const TitleComponent = styled.span({
|
|
43
|
-
|
|
44
|
+
marginTop: token('space.150', '12px'),
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
export const Title = (props) => (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
<Heading level="h200" as="h3">
|
|
49
|
+
<TitleComponent {...props} />
|
|
50
|
+
</Heading>
|
|
50
51
|
);
|
|
51
52
|
```
|
|
52
53
|
|
|
@@ -61,7 +62,7 @@ import { styled } from '@compiled/react';
|
|
|
61
62
|
import { elevation } from '@atlaskit/theme';
|
|
62
63
|
|
|
63
64
|
export const ElevationComponent = styled.div`
|
|
64
|
-
|
|
65
|
+
${elevation.e100()};
|
|
65
66
|
`;
|
|
66
67
|
```
|
|
67
68
|
|
|
@@ -72,16 +73,17 @@ import { styled } from '@compiled/react';
|
|
|
72
73
|
import { token } from '@atlaskit/tokens';
|
|
73
74
|
|
|
74
75
|
export const TestComponent = styled.div({
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
boxShadow: token(
|
|
77
|
+
'elevation.shadow.raised',
|
|
78
|
+
'0 1px 1px rgba(9,30,66,0.25),0 0 1px 1px rgba(9,30,66,0.13)',
|
|
79
|
+
),
|
|
79
80
|
});
|
|
80
81
|
```
|
|
81
82
|
|
|
82
83
|
### Skeleton Shimmer
|
|
83
84
|
|
|
84
|
-
You can preview our `@atlaskit/skeleton` (docs available to internal Atlassians only:
|
|
85
|
+
You can preview our `@atlaskit/skeleton` (docs available to internal Atlassians only:
|
|
86
|
+
[link](https://staging.atlassian.design/components/skeleton/examples)).
|
|
85
87
|
|
|
86
88
|
Otherwise, please use an SVG skeleton or your own `@compiled/react` variant yourself.
|
|
87
89
|
|
|
@@ -92,7 +94,7 @@ import { styled } from '@compiled/react';
|
|
|
92
94
|
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
93
95
|
|
|
94
96
|
export const SkeletonShimmerComponent = styled.div`
|
|
95
|
-
|
|
97
|
+
${skeletonShimmer};
|
|
96
98
|
`;
|
|
97
99
|
```
|
|
98
100
|
|
|
@@ -100,10 +102,10 @@ export const SkeletonShimmerComponent = styled.div`
|
|
|
100
102
|
|
|
101
103
|
```tsx
|
|
102
104
|
export const SkeletonShimmerComponent = () => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
return (
|
|
106
|
+
<Wrapper>
|
|
107
|
+
<object data="./skeleton.svg" type="image/svg+xml"></object>
|
|
108
|
+
</Wrapper>
|
|
109
|
+
);
|
|
108
110
|
};
|
|
109
111
|
```
|
|
@@ -3,19 +3,19 @@ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
|
3
3
|
import rule from '../index';
|
|
4
4
|
|
|
5
5
|
const valid = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
{
|
|
7
|
+
name: 'Valid typography use in styled-components',
|
|
8
|
+
code: outdent`
|
|
9
9
|
import styled from 'styled-components';
|
|
10
10
|
import { typography } from '@atlaskit/theme';
|
|
11
11
|
export const HeadingComponent = styled.h2\`
|
|
12
12
|
\${typography.h200()};
|
|
13
13
|
\`;
|
|
14
14
|
`,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'Valid typography use in compiled (fontFallback)',
|
|
18
|
+
code: outdent`
|
|
19
19
|
import { styled } from '@compiled/react';
|
|
20
20
|
import { fontFallback } from '@atlaskit/theme/typography';
|
|
21
21
|
import { token } from '@atlaskit/tokens';
|
|
@@ -23,20 +23,20 @@ const valid = [
|
|
|
23
23
|
font: \${token('font.body', fontFallback.body.medium)}
|
|
24
24
|
\`;
|
|
25
25
|
`,
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'Valid elevation use in styled-components',
|
|
29
|
+
code: outdent`
|
|
30
30
|
import styled from 'styled-components';
|
|
31
31
|
import { elevation } from '@atlaskit/theme';
|
|
32
32
|
export const HeadingComponent = styled.h2\`
|
|
33
33
|
\${elevation.e100};
|
|
34
34
|
\`;
|
|
35
35
|
`,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Valid skeleton shimmer use in styled-components',
|
|
39
|
+
code: outdent`
|
|
40
40
|
import styled from 'styled-components';
|
|
41
41
|
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
42
42
|
|
|
@@ -44,13 +44,13 @@ const valid = [
|
|
|
44
44
|
\${skeletonShimmer};
|
|
45
45
|
\`
|
|
46
46
|
`,
|
|
47
|
-
|
|
47
|
+
},
|
|
48
48
|
];
|
|
49
49
|
|
|
50
50
|
const typography = [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
{
|
|
52
|
+
name: 'Invalid typography use in compiled with template expression',
|
|
53
|
+
code: outdent`
|
|
54
54
|
import { styled } from '@compiled/react';
|
|
55
55
|
import { typography } from '@atlaskit/theme';
|
|
56
56
|
|
|
@@ -58,24 +58,24 @@ const typography = [
|
|
|
58
58
|
\${typography.h200()};
|
|
59
59
|
\`;
|
|
60
60
|
`,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
errors: [{ messageId: 'usingTypography' }],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'Invalid typography use in compiled with function call',
|
|
65
|
+
code: outdent`
|
|
66
66
|
import { styled } from '@compiled/react';
|
|
67
67
|
import { typography } from '@atlaskit/theme';
|
|
68
68
|
|
|
69
69
|
export const HeadingComponent = styled.h2(typography.h200());
|
|
70
70
|
`,
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
errors: [{ messageId: 'usingTypography' }],
|
|
72
|
+
},
|
|
73
73
|
];
|
|
74
74
|
|
|
75
75
|
const elevation = [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
{
|
|
77
|
+
name: 'Invalid elevation use in compiled with template expression',
|
|
78
|
+
code: outdent`
|
|
79
79
|
import { styled } from '@compiled/react';
|
|
80
80
|
import { elevation } from '@atlaskit/theme';
|
|
81
81
|
|
|
@@ -83,24 +83,24 @@ const elevation = [
|
|
|
83
83
|
\${elevation.e100()};
|
|
84
84
|
\`;
|
|
85
85
|
`,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
errors: [{ messageId: 'usingElevation' }],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'Invalid elevation use in compiled with function call',
|
|
90
|
+
code: outdent`
|
|
91
91
|
import { styled } from '@compiled/react';
|
|
92
92
|
import { elevation } from '@atlaskit/theme';
|
|
93
93
|
|
|
94
94
|
export const ElevationComponent = styled.div(elevation.e100());
|
|
95
95
|
`,
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
errors: [{ messageId: 'usingElevation' }],
|
|
97
|
+
},
|
|
98
98
|
];
|
|
99
99
|
|
|
100
100
|
const skeletonShimmer = [
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
{
|
|
102
|
+
name: 'Invalid skeleton shimmer use in compiled with template expression',
|
|
103
|
+
code: outdent`
|
|
104
104
|
import { styled } from '@compiled/react';
|
|
105
105
|
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
106
106
|
|
|
@@ -108,26 +108,26 @@ const skeletonShimmer = [
|
|
|
108
108
|
\${skeletonShimmer};
|
|
109
109
|
\`;
|
|
110
110
|
`,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
errors: [{ messageId: 'usingSkeletonShimmer' }],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'Invalid skeleton shimmer use in compiled with function call',
|
|
115
|
+
code: outdent`
|
|
116
116
|
import { styled } from '@compiled/react';
|
|
117
117
|
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
118
118
|
|
|
119
119
|
export const SkeletonShimmerComponent = styled.div(skeletonShimmer);
|
|
120
120
|
`,
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
errors: [{ messageId: 'usingSkeletonShimmer' }],
|
|
122
|
+
},
|
|
123
123
|
];
|
|
124
124
|
|
|
125
125
|
typescriptEslintTester.run(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
'atlaskit-theme',
|
|
127
|
+
// @ts-expect-error
|
|
128
|
+
rule,
|
|
129
|
+
{
|
|
130
|
+
valid,
|
|
131
|
+
invalid: [...typography, ...elevation, ...skeletonShimmer],
|
|
132
|
+
},
|
|
133
133
|
);
|
|
@@ -1,142 +1,134 @@
|
|
|
1
1
|
import type { Rule, Scope } from 'eslint';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
getImportSources,
|
|
5
|
-
isCompiled,
|
|
6
|
-
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
7
4
|
import { createLintRule } from '../utils/create-rule';
|
|
8
5
|
|
|
9
6
|
const isIdentifierReferenced = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
hasImportSpecifier: (def: Scope.Definition) => boolean,
|
|
8
|
+
node: Rule.Node,
|
|
9
|
+
references: Scope.Reference[],
|
|
13
10
|
): boolean =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
11
|
+
references.some(
|
|
12
|
+
(reference) =>
|
|
13
|
+
reference.identifier === node && reference.resolved?.defs.some(hasImportSpecifier),
|
|
14
|
+
);
|
|
19
15
|
|
|
20
16
|
const isTypographyImportSpecifier = (def: Scope.Definition): boolean =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def.parent?.source.value === '@atlaskit/theme/typography');
|
|
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');
|
|
27
22
|
|
|
28
23
|
const isElevationImportSpecifier = (def: Scope.Definition): boolean =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def.parent?.source.value === '@atlaskit/theme/elevation');
|
|
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');
|
|
35
29
|
|
|
36
30
|
const isSkeletonShimmerImportSpecifier = (def: Scope.Definition): boolean =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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');
|
|
43
37
|
|
|
44
38
|
const checkIdentifier = (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
node: Rule.Node,
|
|
40
|
+
context: Rule.RuleContext,
|
|
41
|
+
references: Scope.Reference[],
|
|
48
42
|
) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
|
|
44
|
+
context.report({
|
|
45
|
+
messageId: 'usingTypography',
|
|
46
|
+
node,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
55
49
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
|
|
51
|
+
context.report({
|
|
52
|
+
messageId: 'usingElevation',
|
|
53
|
+
node,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
}
|
|
57
|
+
if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
|
|
58
|
+
context.report({
|
|
59
|
+
messageId: 'usingSkeletonShimmer',
|
|
60
|
+
node,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
71
63
|
};
|
|
72
64
|
|
|
73
65
|
export const rule = createLintRule({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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);
|
|
95
87
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
return {
|
|
89
|
+
'CallExpression Identifier': (node: Rule.Node): void => {
|
|
90
|
+
const { references } = context.getScope();
|
|
91
|
+
const ancestors = context.getAncestors();
|
|
100
92
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
},
|
|
117
109
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
110
|
+
'TaggedTemplateExpression Identifier': (node: Rule.Node): void => {
|
|
111
|
+
const { references } = context.getScope();
|
|
112
|
+
const ancestors = context.getAncestors();
|
|
121
113
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
+
},
|
|
140
132
|
});
|
|
141
133
|
|
|
142
134
|
export default rule;
|