@@ -12,7 +12,9 @@ import {
1212 isJSXIdentifier ,
1313 isJSXMemberExpression ,
1414 isJSXOpeningElement ,
15+ isLiteral ,
1516 isMemberExpression ,
17+ isTemplateLiteral ,
1618 isVariableDeclarator ,
1719 type Node ,
1820} from './nodes'
@@ -161,7 +163,22 @@ export const isPandaProp = (node: TSESTree.JSXAttribute, context: RuleContext<an
161163 return true
162164}
163165
164- const isInPandaFunction = ( node : TSESTree . Property , context : RuleContext < any , any > ) => {
166+ export const isStyledProperty = ( node : TSESTree . Property , context : RuleContext < any , any > , calleeName : string ) => {
167+ if ( ! isIdentifier ( node . key ) && ! isLiteral ( node . key ) && ! isTemplateLiteral ( node . key ) ) return
168+
169+ if ( isIdentifier ( node . key ) && ! isValidProperty ( node . key . name , context , calleeName ) ) return
170+ if (
171+ isLiteral ( node . key ) &&
172+ typeof node . key . value === 'string' &&
173+ ! isValidProperty ( node . key . value , context , calleeName )
174+ )
175+ return
176+ if ( isTemplateLiteral ( node . key ) && ! isValidProperty ( node . key . quasis [ 0 ] . value . raw , context , calleeName ) ) return
177+
178+ return true
179+ }
180+
181+ export const isInPandaFunction = ( node : TSESTree . Property , context : RuleContext < any , any > ) => {
165182 const callAncestor = getAncestor ( isCallExpression , node )
166183 if ( ! callAncestor ) return
167184
@@ -180,20 +197,10 @@ const isInPandaFunction = (node: TSESTree.Property, context: RuleContext<any, an
180197 if ( ! calleeName ) return
181198 if ( ! isPandaIsh ( calleeName , context ) ) return
182199
183- // Ensure attribute is a styled attribute
184- if ( ! isIdentifier ( node . key ) ) return
185- const attr = node . key . name
186- if ( ! isValidProperty ( attr , context , calleeName ) ) return
187-
188- return true
200+ return calleeName
189201}
190202
191- export const isPandaAttribute = ( node : TSESTree . Property , context : RuleContext < any , any > ) => {
192- const callAncestor = getAncestor ( isCallExpression , node )
193-
194- if ( callAncestor ) return isInPandaFunction ( node , context )
195-
196- // Object could be in JSX prop value i.e css prop or a pseudo
203+ export const isInJSXProp = ( node : TSESTree . Property , context : RuleContext < any , any > ) => {
197204 const jsxExprAncestor = getAncestor ( isJSXExpressionContainer , node )
198205 const jsxAttrAncestor = getAncestor ( isJSXAttribute , node )
199206
@@ -204,6 +211,19 @@ export const isPandaAttribute = (node: TSESTree.Property, context: RuleContext<a
204211 return true
205212}
206213
214+ export const isPandaAttribute = ( node : TSESTree . Property , context : RuleContext < any , any > ) => {
215+ const callAncestor = getAncestor ( isCallExpression , node )
216+
217+ if ( callAncestor ) {
218+ const callee = isInPandaFunction ( node , context )
219+ if ( ! callee ) return
220+ return isStyledProperty ( node , context , callee )
221+ }
222+
223+ // Object could be in JSX prop value i.e css prop or a pseudo
224+ return isInJSXProp ( node , context )
225+ }
226+
207227export const resolveLonghand = ( name : string , context : RuleContext < any , any > ) => {
208228 return syncAction ( 'resolveLongHand' , getSyncOpts ( context ) , name )
209229}
0 commit comments