@@ -5,7 +5,8 @@ const testDeprecations = {
5
5
'text.primary' : 'fg.default' ,
6
6
'bg.primary' : 'canvas.default' ,
7
7
'auto.green.5' : [ 'success.fg' , 'success.emphasis' ] ,
8
- 'fade.fg10' : null
8
+ 'fade.fg10' : null ,
9
+ 'autocomplete.shadow' : 'shadow.medium'
9
10
}
10
11
11
12
jest . mock ( '@primer/primitives/dist/deprecations/colors_v2' , ( ) => testDeprecations )
@@ -23,12 +24,16 @@ const ruleTester = new RuleTester({
23
24
ruleTester . run ( 'no-deprecated-colors' , rule , {
24
25
valid : [
25
26
`import {Box} from '@other/design-system'; <Box color="text.primary">Hello</Box>` ,
26
- `import {Box} from '@primer/components'; <Box color="fg.default">Hello</Box>`
27
+ `import {Box} from "@primer/components"; <Box color="fg.default">Hello</Box>` ,
28
+ `import {hello} from "@primer/components"; hello("colors.text.primary")` ,
29
+ `import {themeGet} from "@primer/components"; themeGet("space.text.primary")` ,
30
+ `import {themeGet} from "@other/design-system"; themeGet("colors.text.primary")` ,
31
+ `import {get} from "@other/constants"; get("space.text.primary")`
27
32
] ,
28
33
invalid : [
29
34
{
30
- code : `import {Box} from ' @primer/components' ; function Example() { return <Box color="text.primary">Hello</Box> }` ,
31
- output : `import {Box} from ' @primer/components' ; function Example() { return <Box color="fg.default">Hello</Box> }` ,
35
+ code : `import {Box} from " @primer/components" ; function Example() { return <Box color="text.primary">Hello</Box> }` ,
36
+ output : `import {Box} from " @primer/components" ; function Example() { return <Box color="fg.default">Hello</Box> }` ,
32
37
errors : [
33
38
{
34
39
message : '"text.primary" is deprecated. Use "fg.default" instead.'
@@ -45,43 +50,43 @@ ruleTester.run('no-deprecated-colors', rule, {
45
50
]
46
51
} ,
47
52
{
48
- code : `import {Box} from ' @primer/components' ; const Example = () => <Box color="text.primary">Hello</Box>` ,
49
- output : `import {Box} from ' @primer/components' ; const Example = () => <Box color="fg.default">Hello</Box>` ,
53
+ code : `import {Box} from " @primer/components" ; const Example = () => <Box color="text.primary">Hello</Box>` ,
54
+ output : `import {Box} from " @primer/components" ; const Example = () => <Box color="fg.default">Hello</Box>` ,
50
55
errors : [
51
56
{
52
57
message : '"text.primary" is deprecated. Use "fg.default" instead.'
53
58
}
54
59
]
55
60
} ,
56
61
{
57
- code : `import {Box} from ' @primer/components' ; <Box bg="bg.primary" m={1} />` ,
58
- output : `import {Box} from ' @primer/components' ; <Box bg="canvas.default" m={1} />` ,
62
+ code : `import {Box} from " @primer/components" ; <Box bg="bg.primary" m={1} />` ,
63
+ output : `import {Box} from " @primer/components" ; <Box bg="canvas.default" m={1} />` ,
59
64
errors : [
60
65
{
61
66
message : '"bg.primary" is deprecated. Use "canvas.default" instead.'
62
67
}
63
68
]
64
69
} ,
65
70
{
66
- code : `import {Box} from ' @primer/components' ; <Box color="auto.green.5" />` ,
71
+ code : `import {Box} from " @primer/components" ; <Box color="auto.green.5" />` ,
67
72
errors : [
68
73
{
69
74
message : '"auto.green.5" is deprecated.' ,
70
75
suggestions : [
71
76
{
72
77
desc : 'Use "success.fg" instead.' ,
73
- output : `import {Box} from ' @primer/components' ; <Box color="success.fg" />`
78
+ output : `import {Box} from " @primer/components" ; <Box color="success.fg" />`
74
79
} ,
75
80
{
76
81
desc : 'Use "success.emphasis" instead.' ,
77
- output : `import {Box} from ' @primer/components' ; <Box color="success.emphasis" />`
82
+ output : `import {Box} from " @primer/components" ; <Box color="success.emphasis" />`
78
83
}
79
84
]
80
85
}
81
86
]
82
87
} ,
83
88
{
84
- code : `import {Box} from ' @primer/components' ; <Box color="fade.fg10" />` ,
89
+ code : `import {Box} from " @primer/components" ; <Box color="fade.fg10" />` ,
85
90
errors : [
86
91
{
87
92
message :
@@ -90,8 +95,8 @@ ruleTester.run('no-deprecated-colors', rule, {
90
95
]
91
96
} ,
92
97
{
93
- code : `import {Box, Text} from ' @primer/components' ; <Box bg="bg.primary"><Text color="text.primary">Hello</Text></Box>` ,
94
- output : `import {Box, Text} from ' @primer/components' ; <Box bg="canvas.default"><Text color="fg.default">Hello</Text></Box>` ,
98
+ code : `import {Box, Text} from " @primer/components" ; <Box bg="bg.primary"><Text color="text.primary">Hello</Text></Box>` ,
99
+ output : `import {Box, Text} from " @primer/components" ; <Box bg="canvas.default"><Text color="fg.default">Hello</Text></Box>` ,
95
100
errors : [
96
101
{
97
102
message : '"bg.primary" is deprecated. Use "canvas.default" instead.'
@@ -100,6 +105,42 @@ ruleTester.run('no-deprecated-colors', rule, {
100
105
message : '"text.primary" is deprecated. Use "fg.default" instead.'
101
106
}
102
107
]
108
+ } ,
109
+ {
110
+ code : `import {themeGet} from "@primer/components"; themeGet("colors.text.primary")` ,
111
+ output : `import {themeGet} from "@primer/components"; themeGet("colors.fg.default")` ,
112
+ errors : [
113
+ {
114
+ message : '"colors.text.primary" is deprecated. Use "colors.fg.default" instead.'
115
+ }
116
+ ]
117
+ } ,
118
+ {
119
+ code : `import {themeGet} from "@primer/components"; themeGet("shadows.autocomplete.shadow")` ,
120
+ output : `import {themeGet} from "@primer/components"; themeGet("shadows.shadow.medium")` ,
121
+ errors : [
122
+ {
123
+ message : '"shadows.autocomplete.shadow" is deprecated. Use "shadows.shadow.medium" instead.'
124
+ }
125
+ ]
126
+ } ,
127
+ {
128
+ code : `import {get} from "./constants"; get("colors.text.primary")` ,
129
+ output : `import {get} from "./constants"; get("colors.fg.default")` ,
130
+ errors : [
131
+ {
132
+ message : '"colors.text.primary" is deprecated. Use "colors.fg.default" instead.'
133
+ }
134
+ ]
135
+ } ,
136
+ {
137
+ code : `import {get} from "../constants"; get("colors.text.primary")` ,
138
+ output : `import {get} from "../constants"; get("colors.fg.default")` ,
139
+ errors : [
140
+ {
141
+ message : '"colors.text.primary" is deprecated. Use "colors.fg.default" instead.'
142
+ }
143
+ ]
103
144
}
104
145
]
105
146
} )
0 commit comments