@atlaskit/eslint-plugin-ui-styling-standard 0.11.6 → 0.13.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 (61) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +2 -0
  3. package/constellation/index/overview.mdx +3 -1
  4. package/constellation/no-global-styles/usage.mdx +59 -0
  5. package/constellation/use-compiled/usage.mdx +54 -0
  6. package/dist/cjs/presets/all.codegen.js +3 -1
  7. package/dist/cjs/presets/recommended.codegen.js +3 -1
  8. package/dist/cjs/rules/index.codegen.js +6 -2
  9. package/dist/cjs/rules/no-global-styles/index.js +100 -0
  10. package/dist/cjs/rules/use-compiled/index.js +257 -0
  11. package/dist/cjs/rules/use-compiled/is-safe.js +130 -0
  12. package/dist/cjs/rules/use-compiled/utils.js +26 -0
  13. package/dist/es2019/presets/all.codegen.js +3 -1
  14. package/dist/es2019/presets/recommended.codegen.js +3 -1
  15. package/dist/es2019/rules/index.codegen.js +6 -2
  16. package/dist/es2019/rules/no-global-styles/index.js +67 -0
  17. package/dist/es2019/rules/use-compiled/index.js +182 -0
  18. package/dist/es2019/rules/use-compiled/is-safe.js +118 -0
  19. package/dist/es2019/rules/use-compiled/utils.js +15 -0
  20. package/dist/esm/presets/all.codegen.js +3 -1
  21. package/dist/esm/presets/recommended.codegen.js +3 -1
  22. package/dist/esm/rules/index.codegen.js +6 -2
  23. package/dist/esm/rules/no-global-styles/index.js +94 -0
  24. package/dist/esm/rules/use-compiled/index.js +250 -0
  25. package/dist/esm/rules/use-compiled/is-safe.js +121 -0
  26. package/dist/esm/rules/use-compiled/utils.js +17 -0
  27. package/dist/types/index.codegen.d.ts +4 -0
  28. package/dist/types/presets/all.codegen.d.ts +3 -1
  29. package/dist/types/presets/recommended.codegen.d.ts +3 -1
  30. package/dist/types/rules/index.codegen.d.ts +2 -0
  31. package/dist/types/rules/no-global-styles/index.d.ts +2 -0
  32. package/dist/types/rules/use-compiled/index.d.ts +3 -0
  33. package/dist/types/rules/use-compiled/is-safe.d.ts +10 -0
  34. package/dist/types/rules/use-compiled/utils.d.ts +6 -0
  35. package/dist/types-ts4.5/index.codegen.d.ts +4 -0
  36. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
  37. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
  38. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  39. package/dist/types-ts4.5/rules/no-global-styles/index.d.ts +2 -0
  40. package/dist/types-ts4.5/rules/use-compiled/index.d.ts +3 -0
  41. package/dist/types-ts4.5/rules/use-compiled/is-safe.d.ts +10 -0
  42. package/dist/types-ts4.5/rules/use-compiled/utils.d.ts +6 -0
  43. package/package.json +3 -2
  44. package/src/presets/all.codegen.tsx +3 -1
  45. package/src/presets/recommended.codegen.tsx +3 -1
  46. package/src/rules/index.codegen.tsx +5 -1
  47. package/src/rules/no-global-styles/README.md +56 -0
  48. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +33 -0
  49. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +46 -0
  50. package/src/rules/no-global-styles/index.tsx +85 -0
  51. package/src/rules/use-compiled/README.md +49 -0
  52. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +73 -0
  53. package/src/rules/use-compiled/__tests__/css.test.tsx +126 -0
  54. package/src/rules/use-compiled/__tests__/imports.test.tsx +163 -0
  55. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +140 -0
  56. package/src/rules/use-compiled/__tests__/pragma.test.tsx +108 -0
  57. package/src/rules/use-compiled/__tests__/styled.test.tsx +114 -0
  58. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +15 -0
  59. package/src/rules/use-compiled/index.tsx +275 -0
  60. package/src/rules/use-compiled/is-safe.tsx +163 -0
  61. package/src/rules/use-compiled/utils.tsx +37 -0
@@ -0,0 +1,163 @@
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 - ignored', rule, {
14
+ valid: [
15
+ {
16
+ name: '[@atlaskit/primitives.xcss] - is ignored (it\'s okay to use, for now)',
17
+ code: `
18
+ import { xcss, Box } from '@atlaskit/primitives';
19
+ `,
20
+ },
21
+ {
22
+ name: '[@atlaskit/css] - is ignored (it\'s okay to use)',
23
+ code: `
24
+ import { cssMap, keyframes } from '@atlaskit/css';
25
+ `,
26
+ },
27
+ {
28
+ name: '[@stylexjs/stylex] - is ignored (we don\'t maintain a list of all CSS-in-JS libraries, but we could)',
29
+ code: `
30
+ import * as stylex from '@stylexjs/stylex';
31
+ `,
32
+ }
33
+ ],
34
+ invalid: [],
35
+ });
36
+
37
+ tester.run('imports - fixable', rule, {
38
+ valid: [],
39
+ invalid: [
40
+ {
41
+ name: '[@emotion/core] - supported imports with aliasing',
42
+ code: `
43
+ import { css as c, keyframes as kf } from '@emotion/core';
44
+ `,
45
+ output: `
46
+ import { css as c, keyframes as kf } from '@compiled/react';
47
+ `,
48
+ errors: [{ messageId: 'use-compiled' }],
49
+ options: [{ canAutoFix: true }],
50
+ },
51
+ {
52
+ name: '[@emotion/react] - supported imports with aliasing',
53
+ code: `
54
+ import { css as c, keyframes as kf } from '@emotion/react';
55
+ `,
56
+ output: `
57
+ import { css as c, keyframes as kf } from '@compiled/react';
58
+ `,
59
+ errors: [{ messageId: 'use-compiled' }],
60
+ options: [{ canAutoFix: true }],
61
+ },
62
+ {
63
+ name: '[@emotion/styled] - supported imports with aliasing',
64
+ code: `
65
+ import s from '@emotion/styled';
66
+ `,
67
+ output: `
68
+ import { styled as s } from '@compiled/react';
69
+ `,
70
+ errors: [{ messageId: 'use-compiled' }],
71
+ options: [{ canAutoFix: true }],
72
+ },
73
+ {
74
+ name: '[styled-components] - supported imports with aliasing',
75
+ code: `
76
+ import s, { css as c, keyframes as kf } from 'styled-components';
77
+ `,
78
+ output: `
79
+ import { css as c, keyframes as kf, styled as s } from '@compiled/react';
80
+ `,
81
+ errors: [{ messageId: 'use-compiled' }],
82
+ options: [{ canAutoFix: true }],
83
+ },
84
+ {
85
+ name: '[@emotion/core] - with existing compiled import',
86
+ code: outdent`
87
+ import { css } from '@emotion/core';
88
+ import { styled } from '@compiled/react';
89
+ `,
90
+ output: outdent`
91
+
92
+ import { styled, css } from '@compiled/react';
93
+ `,
94
+ errors: [{ messageId: 'use-compiled' }],
95
+ options: [{ canAutoFix: true }],
96
+ },
97
+ {
98
+ name: '[@emotion/react] - with existing compiled import',
99
+ code: outdent`
100
+ import { css } from '@emotion/react';
101
+ import { styled } from '@compiled/react';
102
+ `,
103
+ output: outdent`
104
+
105
+ import { styled, css } from '@compiled/react';
106
+ `,
107
+ errors: [{ messageId: 'use-compiled' }],
108
+ options: [{ canAutoFix: true }],
109
+ },
110
+ {
111
+ name: '[@emotion/styled] - with existing compiled import',
112
+ code: outdent`
113
+ import styled from '@emotion/styled';
114
+ import { css } from '@compiled/react';
115
+ `,
116
+ output: outdent`
117
+
118
+ import { css, styled } from '@compiled/react';
119
+ `,
120
+ errors: [{ messageId: 'use-compiled' }],
121
+ options: [{ canAutoFix: true }],
122
+ },
123
+ {
124
+ name: '[styled-components] - with existing compiled import',
125
+ code: outdent`
126
+ import styled from 'styled-components';
127
+ import { css } from '@compiled/react';
128
+ `,
129
+ output: outdent`
130
+
131
+ import { css, styled } from '@compiled/react';
132
+ `,
133
+ errors: [{ messageId: 'use-compiled' }],
134
+ options: [{ canAutoFix: true }],
135
+ },
136
+ ],
137
+ });
138
+
139
+ /**
140
+ * These test cases have no auto-fix because we are considering
141
+ * them unsafe to automatically convert.
142
+ */
143
+ tester.run('imports - not fixable', rule, {
144
+ valid: [],
145
+ invalid: importSources.flatMap((importSource) => [
146
+ {
147
+ name: `[${importSource}] namespace import`,
148
+ code: `
149
+ import * as namespace from '${importSource}';
150
+ `,
151
+ errors: [{ messageId: 'use-compiled' }],
152
+ options: [{ canAutoFix: true }],
153
+ },
154
+ {
155
+ name: `[${importSource}] unsupported import`,
156
+ code: `
157
+ import { type CSSObject } from '${importSource}';
158
+ `,
159
+ errors: [{ messageId: 'use-compiled' }],
160
+ options: [{ canAutoFix: true }],
161
+ },
162
+ ]),
163
+ });
@@ -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
+ });
@@ -0,0 +1,114 @@
1
+ import { tester } from '../../__tests__/utils/_tester';
2
+ import rule from '../index';
3
+
4
+ tester.run('styled API - fixable', rule, {
5
+ valid: [],
6
+ invalid: ['@emotion/styled', 'styled-components'].flatMap((importSource) => [
7
+ {
8
+ name: `[${importSource}] styles are a plain object with literal values`,
9
+ code: `
10
+ import styled from '${importSource}';
11
+
12
+ const Component = styled.div({
13
+ color: 'red',
14
+ });
15
+ `,
16
+ output: `
17
+ import { styled } from '@compiled/react';
18
+
19
+ const Component = styled.div({
20
+ color: 'red',
21
+ });
22
+ `,
23
+ errors: [{ messageId: 'use-compiled' }],
24
+ options: [{ canAutoFix: true }],
25
+ },
26
+ ]),
27
+ });
28
+
29
+ /**
30
+ * These test cases have no auto-fix because we are considering
31
+ * them unsafe to automatically convert.
32
+ */
33
+ tester.run('styled API - not fixable', rule, {
34
+ valid: [],
35
+ invalid: ['@emotion/styled', 'styled-components'].flatMap((importSource) => [
36
+ {
37
+ name: `[${importSource}] function as style argument`,
38
+ code: `
39
+ import styled from '${importSource}';
40
+
41
+ const Component = styled.div(() => ({
42
+ color: 'red',
43
+ }));
44
+ `,
45
+ errors: [{ messageId: 'use-compiled' }],
46
+ options: [{ canAutoFix: true }],
47
+ },
48
+ {
49
+ name: `[${importSource}] function as style object value`,
50
+ code: `
51
+ import styled from '${importSource}';
52
+
53
+ const Component = styled.div({
54
+ color: () => 'red',
55
+ });
56
+ `,
57
+ errors: [{ messageId: 'use-compiled' }],
58
+ options: [{ canAutoFix: true }],
59
+ },
60
+ {
61
+ name: `[${importSource}] identifier as style object value`,
62
+ code: `
63
+ import styled from '${importSource}';
64
+
65
+ const textColor = 'red';
66
+ const Component = styled.div({
67
+ color: textColor,
68
+ });
69
+ `,
70
+ errors: [{ messageId: 'use-compiled' }],
71
+ options: [{ canAutoFix: true }],
72
+ },
73
+ {
74
+ /**
75
+ * We could auto-fix this safely but intentionally
76
+ * keeping this rule very simple for now.
77
+ */
78
+ name: `[${importSource}] function call as style object value`,
79
+ code: `
80
+ import styled from '${importSource}';
81
+ import { token } from '@atlaskit/tokens';
82
+
83
+ const Component = styled.div({
84
+ color: token('color.text'),
85
+ });
86
+ `,
87
+ errors: [{ messageId: 'use-compiled' }],
88
+ options: [{ canAutoFix: true }],
89
+ },
90
+ {
91
+ name: `[${importSource}] styled call extends component`,
92
+ code: `
93
+ import styled from '${importSource}';
94
+ import { BaseComponent } from './base-component';
95
+
96
+ const Component = styled(BaseComponent)({});
97
+ `,
98
+ errors: [{ messageId: 'use-compiled' }],
99
+ options: [{ canAutoFix: true }],
100
+ },
101
+ {
102
+ name: `[${importSource}] with unsupported named import`,
103
+ code: `
104
+ import styled, { type CSSObject } from '${importSource}';
105
+
106
+ const Component = styled.div({
107
+ color: 'red',
108
+ });
109
+ `,
110
+ errors: [{ messageId: 'use-compiled' }],
111
+ options: [{ canAutoFix: true }],
112
+ },
113
+ ]),
114
+ });
@@ -0,0 +1,15 @@
1
+ import { tester } from '../../__tests__/utils/_tester';
2
+ import rule from '../index';
3
+
4
+ tester.run('use-compiled', rule, {
5
+ valid: [
6
+ `import { styled } from '@compiled/react';`,
7
+ `import { css } from '@compiled/react';`,
8
+ `import { ClassNames } from '@compiled/react';`,
9
+ `import { css, ClassNames, styled } from '@compiled/react';`,
10
+ `import '@compiled/react'`,
11
+ `/** @jsx jsx */`,
12
+ `/** @jsxImportSource @compiled/react */`,
13
+ ],
14
+ invalid: [],
15
+ });