@@ -5,13 +5,28 @@ const styledSystemColorProps = ['color', 'bg', 'backgroundColor', 'borderColor',
5
5
module . exports = {
6
6
meta : {
7
7
type : 'suggestion' ,
8
- fixable : 'code'
8
+ fixable : 'code' ,
9
+ schema : [
10
+ {
11
+ type : 'object' ,
12
+ properties : {
13
+ checkImport : {
14
+ type : 'boolean'
15
+ }
16
+ } ,
17
+ additionalProperties : false
18
+ }
19
+ ]
9
20
} ,
10
21
create ( context ) {
22
+ // If `shouldCheckImport` is true, this rule will only check for deprecated colors
23
+ // used in functions and components that are imported from `@primer/components`.
24
+ const shouldCheckImport = context . options [ 0 ] ? context . options [ 0 ] . checkImport : true
25
+
11
26
return {
12
27
JSXOpeningElement ( node ) {
13
28
// Skip if component was not imported from @primer /components
14
- if ( ! isPrimerComponent ( node . name , context . getScope ( node ) ) ) {
29
+ if ( shouldCheckImport && ! isPrimerComponent ( node . name , context . getScope ( node ) ) ) {
15
30
return
16
31
}
17
32
@@ -49,7 +64,10 @@ module.exports = {
49
64
CallExpression ( node ) {
50
65
// Skip if not calling the `themeGet` or `get` function
51
66
// `get` is the internal version of `themeGet` that's used in the primer/react repository
52
- if ( ! isThemeGet ( node . callee , context . getScope ( node ) ) && ! isGet ( node . callee , context . getScope ( node ) ) ) {
67
+ if (
68
+ ! isThemeGet ( node . callee , context . getScope ( node ) , shouldCheckImport ) &&
69
+ ! isGet ( node . callee , context . getScope ( node ) )
70
+ ) {
53
71
return
54
72
}
55
73
@@ -95,11 +113,17 @@ function isPrimerComponent(identifier, scope) {
95
113
return isImportedFrom ( / ^ @ p r i m e r \/ c o m p o n e n t s / , identifier , scope )
96
114
}
97
115
98
- function isThemeGet ( identifier , scope ) {
99
- return isImportedFrom ( / ^ @ p r i m e r \/ c o m p o n e n t s / , identifier , scope ) && identifier . name === 'themeGet'
116
+ function isThemeGet ( identifier , scope , shouldCheckImport = true ) {
117
+ if ( shouldCheckImport ) {
118
+ return isImportedFrom ( / ^ @ p r i m e r \/ c o m p o n e n t s / , identifier , scope ) && identifier . name === 'themeGet'
119
+ }
120
+
121
+ return identifier . name === 'themeGet'
100
122
}
101
123
124
+ // `get` is the internal version of `themeGet` that's used in the primer/react repository.
102
125
function isGet ( identifier , scope ) {
126
+ // This is a flaky way to check for the `get` function and should probably be improved.
103
127
return isImportedFrom ( / ^ \. \. ? \/ c o n s t a n t s $ / , identifier , scope ) && identifier . name === 'get'
104
128
}
105
129
0 commit comments