@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,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::be177a361ddc1a7a41d843680299e318>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
|
+
import atlaskitTheme from './atlaskit-theme';
|
|
6
7
|
import convertPropsSyntax from './convert-props-syntax';
|
|
7
8
|
import enforceStyleProp from './enforce-style-prop';
|
|
8
9
|
import localCxXcss from './local-cx-xcss';
|
|
@@ -15,18 +16,21 @@ import noImportantStyles from './no-important-styles';
|
|
|
15
16
|
import noImportedStyleValues from './no-imported-style-values';
|
|
16
17
|
import noNestedSelectors from './no-nested-selectors';
|
|
17
18
|
import noUnsafeValues from './no-unsafe-values';
|
|
19
|
+
import useCompiled from './use-compiled';
|
|
18
20
|
|
|
19
21
|
export default {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
'atlaskit-theme': atlaskitTheme,
|
|
23
|
+
'convert-props-syntax': convertPropsSyntax,
|
|
24
|
+
'enforce-style-prop': enforceStyleProp,
|
|
25
|
+
'local-cx-xcss': localCxXcss,
|
|
26
|
+
'no-array-arguments': noArrayArguments,
|
|
27
|
+
'no-classname-prop': noClassnameProp,
|
|
28
|
+
'no-container-queries': noContainerQueries,
|
|
29
|
+
'no-dynamic-styles': noDynamicStyles,
|
|
30
|
+
'no-exported-styles': noExportedStyles,
|
|
31
|
+
'no-important-styles': noImportantStyles,
|
|
32
|
+
'no-imported-style-values': noImportedStyleValues,
|
|
33
|
+
'no-nested-selectors': noNestedSelectors,
|
|
34
|
+
'no-unsafe-values': noUnsafeValues,
|
|
35
|
+
'use-compiled': useCompiled,
|
|
32
36
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Ensures usage of `@compiled/react` over other CSS-in-JS libraries.
|
|
2
|
+
|
|
3
|
+
**WARNING**
|
|
4
|
+
|
|
5
|
+
It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries.
|
|
6
|
+
|
|
7
|
+
When converting to `@compiled/react` verify ALL changes.
|
|
8
|
+
|
|
9
|
+
For this reason, the auto-fixer has been disabled by default.
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
### Incorrect
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { css } from '@emotion/core';
|
|
17
|
+
import styled from '@emotion/styled';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
/** @jsx jsx */
|
|
22
|
+
import { jsx } from '@emotion/react';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import styled, { css } from 'styled-components';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Correct
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { css, styled } from '@compiled/react';
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
/** @jsx jsx */
|
|
37
|
+
import { jsx } from '@compiled/react';
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
### `canAutoFix: boolean`
|
|
43
|
+
|
|
44
|
+
Determines whether or not the auto-fixer is enabled.
|
|
45
|
+
|
|
46
|
+
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries.
|
|
47
|
+
|
|
48
|
+
Even when enabled, the auto-fixer will only convert usages that are deemed safe.
|
|
49
|
+
Currently this is limited to purely static styles where all keys and values are simple literals.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { RuleTester } from 'eslint';
|
|
2
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
3
|
+
import rule from '../index';
|
|
4
|
+
|
|
5
|
+
const invalid: RuleTester.InvalidTestCase[] = [
|
|
6
|
+
{
|
|
7
|
+
name: 'css API',
|
|
8
|
+
code: `
|
|
9
|
+
import { css } from '@emotion/react';
|
|
10
|
+
|
|
11
|
+
const Component = css({
|
|
12
|
+
color: 'red',
|
|
13
|
+
});
|
|
14
|
+
`,
|
|
15
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'imports',
|
|
19
|
+
code: `
|
|
20
|
+
import { css as c, keyframes as kf } from '@emotion/core';
|
|
21
|
+
`,
|
|
22
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: `keyframes API`,
|
|
26
|
+
code: `
|
|
27
|
+
import { keyframes } from 'styled-components';
|
|
28
|
+
|
|
29
|
+
const fadeIn = keyframes({
|
|
30
|
+
from: {
|
|
31
|
+
opacity: 0,
|
|
32
|
+
},
|
|
33
|
+
to: {
|
|
34
|
+
opacity: 1,
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
`,
|
|
38
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'pragma fix',
|
|
42
|
+
code: `
|
|
43
|
+
/** @jsxImportSource @emotion/react */
|
|
44
|
+
|
|
45
|
+
import { css } from '@compiled/react';
|
|
46
|
+
`,
|
|
47
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: `styles are a plain object with literal values`,
|
|
51
|
+
code: `
|
|
52
|
+
import styled from '@emotion/styled';
|
|
53
|
+
|
|
54
|
+
const Component = styled.div({
|
|
55
|
+
color: 'red',
|
|
56
|
+
});
|
|
57
|
+
`,
|
|
58
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
tester.run('canAutoFix is not provided', rule, {
|
|
63
|
+
valid: [],
|
|
64
|
+
invalid,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
tester.run('canAutoFix is false', rule, {
|
|
68
|
+
valid: [],
|
|
69
|
+
invalid: invalid.map((testCase) => ({
|
|
70
|
+
...testCase,
|
|
71
|
+
options: [{ canAutoFix: false }],
|
|
72
|
+
})),
|
|
73
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
const importSources = ['@emotion/core', '@emotion/react', 'styled-components'];
|
|
5
|
+
|
|
6
|
+
tester.run('css API - fixable', rule, {
|
|
7
|
+
valid: [],
|
|
8
|
+
invalid: importSources.flatMap((importSource) => [
|
|
9
|
+
{
|
|
10
|
+
name: `[${importSource}] styles are a plain object with literal values`,
|
|
11
|
+
code: `
|
|
12
|
+
import { css } from '${importSource}';
|
|
13
|
+
|
|
14
|
+
const Component = css({
|
|
15
|
+
color: 'red',
|
|
16
|
+
});
|
|
17
|
+
`,
|
|
18
|
+
output: `
|
|
19
|
+
import { css } from '@compiled/react';
|
|
20
|
+
|
|
21
|
+
const Component = css({
|
|
22
|
+
color: 'red',
|
|
23
|
+
});
|
|
24
|
+
`,
|
|
25
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
26
|
+
options: [{ canAutoFix: true }],
|
|
27
|
+
},
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* These test cases have no auto-fix because we are considering
|
|
33
|
+
* them unsafe to automatically convert.
|
|
34
|
+
*/
|
|
35
|
+
tester.run('css API - not fixable', rule, {
|
|
36
|
+
valid: [],
|
|
37
|
+
invalid: importSources.flatMap((importSource) => [
|
|
38
|
+
{
|
|
39
|
+
name: `[${importSource}] function as style argument`,
|
|
40
|
+
code: `
|
|
41
|
+
import { css } from '${importSource}';
|
|
42
|
+
|
|
43
|
+
const Component = css(() => ({
|
|
44
|
+
color: 'red',
|
|
45
|
+
}));
|
|
46
|
+
`,
|
|
47
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
48
|
+
options: [{ canAutoFix: true }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: `[${importSource}] function as style object value`,
|
|
52
|
+
code: `
|
|
53
|
+
import { css } from '${importSource}';
|
|
54
|
+
|
|
55
|
+
const Component = css({
|
|
56
|
+
color: () => 'red',
|
|
57
|
+
});
|
|
58
|
+
`,
|
|
59
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
60
|
+
options: [{ canAutoFix: true }],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: `[${importSource}] identifier as style object value`,
|
|
64
|
+
code: `
|
|
65
|
+
import { css } from '${importSource}';
|
|
66
|
+
|
|
67
|
+
const textColor = 'red';
|
|
68
|
+
const Component = css({
|
|
69
|
+
color: textColor,
|
|
70
|
+
});
|
|
71
|
+
`,
|
|
72
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
73
|
+
options: [{ canAutoFix: true }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
/**
|
|
77
|
+
* We could auto-fix this safely but intentionally
|
|
78
|
+
* keeping this rule very simple for now.
|
|
79
|
+
*/
|
|
80
|
+
name: `[${importSource}] function call as style object value`,
|
|
81
|
+
code: `
|
|
82
|
+
import { css } from '${importSource}';
|
|
83
|
+
import { token } from '@atlaskit/tokens';
|
|
84
|
+
|
|
85
|
+
const Component = css({
|
|
86
|
+
color: token('color.text'),
|
|
87
|
+
});
|
|
88
|
+
`,
|
|
89
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
90
|
+
options: [{ canAutoFix: true }],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: `[${importSource}] with unsupported named import`,
|
|
94
|
+
code: `
|
|
95
|
+
import { css, type CSSObject } from '${importSource}';
|
|
96
|
+
|
|
97
|
+
const Component = css({
|
|
98
|
+
color: 'red',
|
|
99
|
+
});
|
|
100
|
+
`,
|
|
101
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
102
|
+
options: [{ canAutoFix: true }],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: `[${importSource}] with unsafe usage of other import`,
|
|
106
|
+
code: `
|
|
107
|
+
import { css, keyframes } from '${importSource}';
|
|
108
|
+
|
|
109
|
+
const Component = css({
|
|
110
|
+
color: 'red',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const animation = keyframes({
|
|
114
|
+
from: {
|
|
115
|
+
opacity: () => 0
|
|
116
|
+
},
|
|
117
|
+
to: {
|
|
118
|
+
opacity: 1
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
`,
|
|
122
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
123
|
+
options: [{ canAutoFix: true }],
|
|
124
|
+
},
|
|
125
|
+
]),
|
|
126
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import outdent from 'outdent';
|
|
2
|
+
|
|
3
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
4
|
+
import rule from '../index';
|
|
5
|
+
|
|
6
|
+
const importSources = [
|
|
7
|
+
'@emotion/core',
|
|
8
|
+
'@emotion/react',
|
|
9
|
+
'@emotion/styled',
|
|
10
|
+
'styled-components',
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
tester.run('imports - fixable', rule, {
|
|
14
|
+
valid: [],
|
|
15
|
+
invalid: [
|
|
16
|
+
{
|
|
17
|
+
name: '[@emotion/core] - supported imports with aliasing',
|
|
18
|
+
code: `
|
|
19
|
+
import { css as c, keyframes as kf } from '@emotion/core';
|
|
20
|
+
`,
|
|
21
|
+
output: `
|
|
22
|
+
import { css as c, keyframes as kf } from '@compiled/react';
|
|
23
|
+
`,
|
|
24
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
25
|
+
options: [{ canAutoFix: true }],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: '[@emotion/react] - supported imports with aliasing',
|
|
29
|
+
code: `
|
|
30
|
+
import { css as c, keyframes as kf } from '@emotion/react';
|
|
31
|
+
`,
|
|
32
|
+
output: `
|
|
33
|
+
import { css as c, keyframes as kf } from '@compiled/react';
|
|
34
|
+
`,
|
|
35
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
36
|
+
options: [{ canAutoFix: true }],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: '[@emotion/styled] - supported imports with aliasing',
|
|
40
|
+
code: `
|
|
41
|
+
import s from '@emotion/styled';
|
|
42
|
+
`,
|
|
43
|
+
output: `
|
|
44
|
+
import { styled as s } from '@compiled/react';
|
|
45
|
+
`,
|
|
46
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
47
|
+
options: [{ canAutoFix: true }],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: '[styled-components] - supported imports with aliasing',
|
|
51
|
+
code: `
|
|
52
|
+
import s, { css as c, keyframes as kf } from 'styled-components';
|
|
53
|
+
`,
|
|
54
|
+
output: `
|
|
55
|
+
import { css as c, keyframes as kf, styled as s } from '@compiled/react';
|
|
56
|
+
`,
|
|
57
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
58
|
+
options: [{ canAutoFix: true }],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: '[@emotion/core] - with existing compiled import',
|
|
62
|
+
code: outdent`
|
|
63
|
+
import { css } from '@emotion/core';
|
|
64
|
+
import { styled } from '@compiled/react';
|
|
65
|
+
`,
|
|
66
|
+
output: outdent`
|
|
67
|
+
|
|
68
|
+
import { styled, css } from '@compiled/react';
|
|
69
|
+
`,
|
|
70
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
71
|
+
options: [{ canAutoFix: true }],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: '[@emotion/react] - with existing compiled import',
|
|
75
|
+
code: outdent`
|
|
76
|
+
import { css } from '@emotion/react';
|
|
77
|
+
import { styled } from '@compiled/react';
|
|
78
|
+
`,
|
|
79
|
+
output: outdent`
|
|
80
|
+
|
|
81
|
+
import { styled, css } from '@compiled/react';
|
|
82
|
+
`,
|
|
83
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
84
|
+
options: [{ canAutoFix: true }],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: '[@emotion/styled] - with existing compiled import',
|
|
88
|
+
code: outdent`
|
|
89
|
+
import styled from '@emotion/styled';
|
|
90
|
+
import { css } from '@compiled/react';
|
|
91
|
+
`,
|
|
92
|
+
output: outdent`
|
|
93
|
+
|
|
94
|
+
import { css, styled } from '@compiled/react';
|
|
95
|
+
`,
|
|
96
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
97
|
+
options: [{ canAutoFix: true }],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: '[styled-components] - with existing compiled import',
|
|
101
|
+
code: outdent`
|
|
102
|
+
import styled from 'styled-components';
|
|
103
|
+
import { css } from '@compiled/react';
|
|
104
|
+
`,
|
|
105
|
+
output: outdent`
|
|
106
|
+
|
|
107
|
+
import { css, styled } from '@compiled/react';
|
|
108
|
+
`,
|
|
109
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
110
|
+
options: [{ canAutoFix: true }],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* These test cases have no auto-fix because we are considering
|
|
117
|
+
* them unsafe to automatically convert.
|
|
118
|
+
*/
|
|
119
|
+
tester.run('imports - not fixable', rule, {
|
|
120
|
+
valid: [],
|
|
121
|
+
invalid: importSources.flatMap((importSource) => [
|
|
122
|
+
{
|
|
123
|
+
name: `[${importSource}] namespace import`,
|
|
124
|
+
code: `
|
|
125
|
+
import * as namespace from '${importSource}';
|
|
126
|
+
`,
|
|
127
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
128
|
+
options: [{ canAutoFix: true }],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: `[${importSource}] unsupported import`,
|
|
132
|
+
code: `
|
|
133
|
+
import { type CSSObject } from '${importSource}';
|
|
134
|
+
`,
|
|
135
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
136
|
+
options: [{ canAutoFix: true }],
|
|
137
|
+
},
|
|
138
|
+
]),
|
|
139
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
const importSources = ['@emotion/core', '@emotion/react', 'styled-components'];
|
|
5
|
+
|
|
6
|
+
tester.run('keyframes API - fixable', rule, {
|
|
7
|
+
valid: [],
|
|
8
|
+
invalid: importSources.flatMap((importSource) => [
|
|
9
|
+
{
|
|
10
|
+
name: `[${importSource}] styles are a plain object with literal values`,
|
|
11
|
+
code: `
|
|
12
|
+
import { keyframes } from '${importSource}';
|
|
13
|
+
|
|
14
|
+
const fadeIn = keyframes({
|
|
15
|
+
from: {
|
|
16
|
+
opacity: 0,
|
|
17
|
+
},
|
|
18
|
+
to: {
|
|
19
|
+
opacity: 1,
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
`,
|
|
23
|
+
output: `
|
|
24
|
+
import { keyframes } from '@compiled/react';
|
|
25
|
+
|
|
26
|
+
const fadeIn = keyframes({
|
|
27
|
+
from: {
|
|
28
|
+
opacity: 0,
|
|
29
|
+
},
|
|
30
|
+
to: {
|
|
31
|
+
opacity: 1,
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
`,
|
|
35
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
36
|
+
options: [{ canAutoFix: true }],
|
|
37
|
+
},
|
|
38
|
+
]),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* These test cases have no auto-fix because we are considering
|
|
43
|
+
* them unsafe to automatically convert.
|
|
44
|
+
*/
|
|
45
|
+
tester.run('keyframes API - not fixable', rule, {
|
|
46
|
+
valid: [],
|
|
47
|
+
invalid: importSources.flatMap((importSource) => [
|
|
48
|
+
{
|
|
49
|
+
name: `[${importSource}] function as style argument`,
|
|
50
|
+
code: `
|
|
51
|
+
import { keyframes } from '${importSource}';
|
|
52
|
+
|
|
53
|
+
const Component = keyframes(() => ({
|
|
54
|
+
from: {
|
|
55
|
+
opacity: 0,
|
|
56
|
+
},
|
|
57
|
+
to: {
|
|
58
|
+
opacity: 1,
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
`,
|
|
62
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
63
|
+
options: [{ canAutoFix: true }],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: `[${importSource}] function as style object value`,
|
|
67
|
+
code: `
|
|
68
|
+
import { keyframes } from '${importSource}';
|
|
69
|
+
|
|
70
|
+
const Component = keyframes({
|
|
71
|
+
from: {
|
|
72
|
+
opacity: () => 0,
|
|
73
|
+
},
|
|
74
|
+
to: {
|
|
75
|
+
opacity: 1,
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
`,
|
|
79
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
80
|
+
options: [{ canAutoFix: true }],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: `[${importSource}] identifier as style object value`,
|
|
84
|
+
code: `
|
|
85
|
+
import { keyframes } from '${importSource}';
|
|
86
|
+
|
|
87
|
+
const startOpacity = 0;
|
|
88
|
+
const fadeIn = keyframes({
|
|
89
|
+
from: {
|
|
90
|
+
opacity: startOpacity,
|
|
91
|
+
},
|
|
92
|
+
to: {
|
|
93
|
+
opacity: 1,
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
`,
|
|
97
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
98
|
+
options: [{ canAutoFix: true }],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
/**
|
|
102
|
+
* We could auto-fix this safely but intentionally
|
|
103
|
+
* keeping this rule very simple for now.
|
|
104
|
+
*/
|
|
105
|
+
name: `[${importSource}] function call as style object value`,
|
|
106
|
+
code: `
|
|
107
|
+
import { keyframes } from '${importSource}';
|
|
108
|
+
import { token } from '@atlaskit/tokens';
|
|
109
|
+
|
|
110
|
+
const hideBackground = keyframes({
|
|
111
|
+
from: {
|
|
112
|
+
backgroundColor: token('color.background.neutral'),
|
|
113
|
+
},
|
|
114
|
+
to: {
|
|
115
|
+
backgroundColor: 'transparent',
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
`,
|
|
119
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
120
|
+
options: [{ canAutoFix: true }],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: `[${importSource}] with unsupported named import`,
|
|
124
|
+
code: `
|
|
125
|
+
import { keyframes, type CSSObject } from '${importSource}';
|
|
126
|
+
|
|
127
|
+
const fadeIn = keyframes({
|
|
128
|
+
from: {
|
|
129
|
+
opacity: 0,
|
|
130
|
+
},
|
|
131
|
+
to: {
|
|
132
|
+
opacity: 1,
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
`,
|
|
136
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
137
|
+
options: [{ canAutoFix: true }],
|
|
138
|
+
},
|
|
139
|
+
]),
|
|
140
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('jsxImportSource pragma - fixable', rule, {
|
|
5
|
+
valid: [],
|
|
6
|
+
invalid: ['@emotion/core', '@emotion/react']
|
|
7
|
+
.flatMap((importSource) => [
|
|
8
|
+
{
|
|
9
|
+
name: `[${importSource}] fixable import exists`,
|
|
10
|
+
code: `
|
|
11
|
+
/** @jsxImportSource @emotion/react */
|
|
12
|
+
|
|
13
|
+
import { css } from '${importSource}';
|
|
14
|
+
`,
|
|
15
|
+
/**
|
|
16
|
+
* This output does not have a fixed pragma because the rule tester
|
|
17
|
+
* only does a single pass of the fixers.
|
|
18
|
+
*
|
|
19
|
+
* In reality up to 10 passes are done. We can see that from this state
|
|
20
|
+
* the pragma does get fixed in the test below.
|
|
21
|
+
*/
|
|
22
|
+
output: `
|
|
23
|
+
/** @jsxImportSource @emotion/react */
|
|
24
|
+
|
|
25
|
+
import { css } from '@compiled/react';
|
|
26
|
+
`,
|
|
27
|
+
errors: [{ messageId: 'use-compiled' }, { messageId: 'use-compiled' }],
|
|
28
|
+
options: [{ canAutoFix: true }],
|
|
29
|
+
},
|
|
30
|
+
])
|
|
31
|
+
.concat([
|
|
32
|
+
{
|
|
33
|
+
name: `[@emotion/styled] fixable import exists`,
|
|
34
|
+
code: `
|
|
35
|
+
/** @jsxImportSource @emotion/react */
|
|
36
|
+
|
|
37
|
+
import styled from '@emotion/styled';
|
|
38
|
+
`,
|
|
39
|
+
/**
|
|
40
|
+
* This output does not have a fixed pragma because the rule tester
|
|
41
|
+
* only does a single pass of the fixers.
|
|
42
|
+
*
|
|
43
|
+
* In reality up to 10 passes are done. We can see that from this state
|
|
44
|
+
* the pragma does get fixed in the test below.
|
|
45
|
+
*/
|
|
46
|
+
output: `
|
|
47
|
+
/** @jsxImportSource @emotion/react */
|
|
48
|
+
|
|
49
|
+
import { styled } from '@compiled/react';
|
|
50
|
+
`,
|
|
51
|
+
errors: [{ messageId: 'use-compiled' }, { messageId: 'use-compiled' }],
|
|
52
|
+
options: [{ canAutoFix: true }],
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'no @emotion imports and has @compiled/react import',
|
|
56
|
+
code: `
|
|
57
|
+
/** @jsxImportSource @emotion/react */
|
|
58
|
+
|
|
59
|
+
import { css } from '@compiled/react';
|
|
60
|
+
`,
|
|
61
|
+
output: `
|
|
62
|
+
/** @jsxImportSource @compiled/react */
|
|
63
|
+
|
|
64
|
+
import { css } from '@compiled/react';
|
|
65
|
+
`,
|
|
66
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
67
|
+
options: [{ canAutoFix: true }],
|
|
68
|
+
},
|
|
69
|
+
]),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
tester.run('jsxImportSource pragma - not fixable', rule, {
|
|
73
|
+
valid: [],
|
|
74
|
+
invalid: [
|
|
75
|
+
{
|
|
76
|
+
name: 'no @compiled/react import',
|
|
77
|
+
code: `/** @jsxImportSource @emotion/react */`,
|
|
78
|
+
errors: [{ messageId: 'use-compiled' }],
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'non-fixable @emotion/core import exists',
|
|
82
|
+
code: `
|
|
83
|
+
/** @jsxImportSource @emotion/react */
|
|
84
|
+
|
|
85
|
+
import { type CSSObject } from '@emotion/core';
|
|
86
|
+
`,
|
|
87
|
+
errors: [{ messageId: 'use-compiled' }, { messageId: 'use-compiled' }],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'non-fixable @emotion/react import exists',
|
|
91
|
+
code: `
|
|
92
|
+
/** @jsxImportSource @emotion/react */
|
|
93
|
+
|
|
94
|
+
import { type CSSObject } from '@emotion/react';
|
|
95
|
+
`,
|
|
96
|
+
errors: [{ messageId: 'use-compiled' }, { messageId: 'use-compiled' }],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'non-fixable @emotion/styled import exists',
|
|
100
|
+
code: `
|
|
101
|
+
/** @jsxImportSource @emotion/react */
|
|
102
|
+
|
|
103
|
+
import { type CSSObject } from '@emotion/styled';
|
|
104
|
+
`,
|
|
105
|
+
errors: [{ messageId: 'use-compiled' }, { messageId: 'use-compiled' }],
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
});
|