@@ -155,28 +155,14 @@ export default createEslintRule<Options, MESSAGE_ID>({
155155 return
156156 }
157157
158- let isStyledCallExpression = ( identifier : TSESTree . Expression ) : boolean =>
159- identifier . type === 'Identifier' && identifier . name === 'styled'
160- let isCssCallExpression = ( identifier : TSESTree . Expression ) : boolean =>
161- identifier . type === 'Identifier' && identifier . name === 'css'
162- let isStyledComponents = (
163- styledNode : TSESTree . Node | undefined ,
164- ) : boolean =>
165- ! ! styledNode &&
166- ( ( styledNode . type === 'CallExpression' &&
167- ( isCssCallExpression ( styledNode . callee ) ||
168- ( styledNode . callee . type === 'MemberExpression' &&
169- isStyledCallExpression ( styledNode . callee . object ) ) ||
170- ( styledNode . callee . type === 'CallExpression' &&
171- isStyledCallExpression ( styledNode . callee . callee ) ) ) ) ||
172- ( styledNode . type === 'JSXExpressionContainer' &&
173- styledNode . parent . type === 'JSXAttribute' &&
174- styledNode . parent . name . name === 'style' ) )
158+ let objectRoot =
159+ nodeObject . type === 'ObjectPattern' ? null : getRootObject ( nodeObject )
175160 if (
161+ objectRoot &&
176162 ! options . styledComponents &&
177- ( isStyledComponents ( nodeObject . parent ) ||
178- ( nodeObject . parent . type === 'ArrowFunctionExpression' &&
179- isStyledComponents ( nodeObject . parent . parent ) ) )
163+ ( isStyledComponents ( objectRoot . parent ) ||
164+ ( objectRoot . parent . type === 'ArrowFunctionExpression' &&
165+ isStyledComponents ( objectRoot . parent . parent ) ) )
180166 ) {
181167 return
182168 }
@@ -575,6 +561,19 @@ let getObjectParent = ({
575561 return null
576562}
577563
564+ let getRootObject = (
565+ node : TSESTree . ObjectExpression ,
566+ ) : TSESTree . ObjectExpression => {
567+ let objectRoot = node
568+ while (
569+ objectRoot . parent . type === 'Property' &&
570+ objectRoot . parent . parent . type === 'ObjectExpression'
571+ ) {
572+ objectRoot = objectRoot . parent . parent
573+ }
574+ return objectRoot
575+ }
576+
578577let getVariableParentName = ( {
579578 onlyFirstParent,
580579 node,
@@ -624,3 +623,31 @@ let getCallExpressionParentName = ({
624623
625624 return callParent . callee . type === 'Identifier' ? callParent . callee . name : null
626625}
626+
627+ let isStyledCallExpression = ( identifier : TSESTree . Expression ) : boolean =>
628+ identifier . type === 'Identifier' && identifier . name === 'styled'
629+
630+ let isCssCallExpression = ( identifier : TSESTree . Expression ) : boolean =>
631+ identifier . type === 'Identifier' && identifier . name === 'css'
632+
633+ let isStyledComponents = ( styledNode : TSESTree . Node ) : boolean => {
634+ if (
635+ styledNode . type === 'JSXExpressionContainer' &&
636+ styledNode . parent . type === 'JSXAttribute' &&
637+ styledNode . parent . name . name === 'style'
638+ ) {
639+ return true
640+ }
641+
642+ if ( styledNode . type !== 'CallExpression' ) {
643+ return false
644+ }
645+
646+ return (
647+ isCssCallExpression ( styledNode . callee ) ||
648+ ( styledNode . callee . type === 'MemberExpression' &&
649+ isStyledCallExpression ( styledNode . callee . object ) ) ||
650+ ( styledNode . callee . type === 'CallExpression' &&
651+ isStyledCallExpression ( styledNode . callee . callee ) )
652+ )
653+ }
0 commit comments