Skip to content

Commit 7ecd6ad

Browse files
committed
fix: improve nested styling detection in no-invalid-nesting rule
1 parent 6c2b6cd commit 7ecd6ad

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

.changeset/light-cooks-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@pandacss/eslint-plugin": patch
3+
---
4+
5+
Improve nested styling detection in `no-invalid-nesting` rule

plugin/src/rules/no-invalid-nesting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isIdentifier, isLiteral, isObjectExpression, isTemplateLiteral } from '../utils/nodes'
22
import { type Rule, createRule } from '../utils'
3-
import { isInJSXProp, isInPandaFunction } from '../utils/helpers'
3+
import { isPandaAttribute } from '../utils/helpers'
44

55
export const RULE_NAME = 'no-invalid-nesting'
66

@@ -21,7 +21,7 @@ const rule: Rule = createRule({
2121
return {
2222
Property(node) {
2323
if (!isObjectExpression(node.value) || isIdentifier(node.key)) return
24-
if (!isInPandaFunction(node, context) && !isInJSXProp(node, context)) return
24+
if (isPandaAttribute(node, context)) return
2525

2626
const invalidLiteral =
2727
isLiteral(node.key) && typeof node.key.value === 'string' && !node.key.value.includes('&')

plugin/src/utils/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export const isPandaProp = (node: TSESTree.JSXAttribute, context: RuleContext<an
163163
return true
164164
}
165165

166-
export const isStyledProperty = (node: TSESTree.Property, context: RuleContext<any, any>, calleeName: string) => {
166+
export const isStyledProperty = (node: TSESTree.Property, context: RuleContext<any, any>, calleeName?: string) => {
167167
if (!isIdentifier(node.key) && !isLiteral(node.key) && !isTemplateLiteral(node.key)) return
168168

169169
if (isIdentifier(node.key) && !isValidProperty(node.key.name, context, calleeName)) return
@@ -221,7 +221,7 @@ export const isPandaAttribute = (node: TSESTree.Property, context: RuleContext<a
221221
}
222222

223223
// Object could be in JSX prop value i.e css prop or a pseudo
224-
return isInJSXProp(node, context)
224+
return isInJSXProp(node, context) && isStyledProperty(node, context)
225225
}
226226

227227
export const resolveLonghand = (name: string, context: RuleContext<any, any>) => {

0 commit comments

Comments
 (0)