Skip to content

Commit

Permalink
fix: improve nested styling detection in no-invalid-nesting rule
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 committed Feb 10, 2024
1 parent 6c2b6cd commit 7ecd6ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-cooks-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pandacss/eslint-plugin": patch
---

Improve nested styling detection in `no-invalid-nesting` rule
4 changes: 2 additions & 2 deletions plugin/src/rules/no-invalid-nesting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isIdentifier, isLiteral, isObjectExpression, isTemplateLiteral } from '../utils/nodes'
import { type Rule, createRule } from '../utils'
import { isInJSXProp, isInPandaFunction } from '../utils/helpers'
import { isPandaAttribute } from '../utils/helpers'

export const RULE_NAME = 'no-invalid-nesting'

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

const invalidLiteral =
isLiteral(node.key) && typeof node.key.value === 'string' && !node.key.value.includes('&')
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const isPandaProp = (node: TSESTree.JSXAttribute, context: RuleContext<an
return true
}

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

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

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

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

0 comments on commit 7ecd6ad

Please sign in to comment.