Skip to content

Commit 7d43577

Browse files
committed
fix: account for escape hatch
1 parent 9e43308 commit 7d43577

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

plugin/src/rules/no-important.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isPandaAttribute, isPandaProp } from '../utils/helpers'
22
import { type Rule, createRule } from '../utils'
33
import { isIdentifier, isJSXExpressionContainer, isLiteral, isTemplateLiteral, type Node } from '../utils/nodes'
4+
import { getArbitraryValue } from '@pandacss/shared'
45

56
// Check if the string ends with '!' with optional whitespace before it
67
const exclamationRegex = /\s*!$/
@@ -29,8 +30,9 @@ const rule: Rule = createRule({
2930
create(context) {
3031
const removeQuotes = ([start, end]: readonly [number, number]) => [start + 1, end - 1] as const
3132

32-
const hasImportantKeyword = (value?: string) => {
33-
if (!value) return false
33+
const hasImportantKeyword = (_value?: string) => {
34+
if (!_value) return false
35+
const value = getArbitraryValue(_value)
3436
return exclamationRegex.test(value) || importantRegex.test(value)
3537
}
3638

plugin/src/rules/no-unsafe-token-fn-usage.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isTemplateLiteral,
1010
type Node,
1111
} from '../utils/nodes'
12+
import { getArbitraryValue } from '@pandacss/shared'
1213

1314
export const RULE_NAME = 'no-unsafe-token-fn-usage'
1415

@@ -43,10 +44,10 @@ const rule: Rule = createRule({
4344
const value = node.arguments[0]
4445

4546
if (isLiteral(value)) {
46-
sendReport(node, tokenWrap(value.value?.toString()))
47+
sendReport(node, tokenWrap(getArbitraryValue(value.value?.toString() ?? '')))
4748
}
4849
if (isTemplateLiteral(value)) {
49-
sendReport(node, tokenWrap(value.quasis[0].value.raw))
50+
sendReport(node, tokenWrap(getArbitraryValue(value.quasis[0].value.raw)))
5051
}
5152
}
5253

@@ -59,20 +60,20 @@ const rule: Rule = createRule({
5960

6061
const handleLiteral = (node: Node) => {
6162
if (!isLiteral(node)) return
62-
if (isCompositeValue(node.value?.toString())) return
63+
const value = getArbitraryValue(node.value?.toString() ?? '')
64+
if (isCompositeValue(value)) return
6365

64-
sendReport(node)
66+
sendReport(node, value)
6567
}
6668

6769
const handleTemplateLiteral = (node: Node) => {
6870
if (!isTemplateLiteral(node)) return
6971
if (node.expressions.length > 0) return
7072

71-
sendReport(node, node.quasis[0].value.raw)
73+
sendReport(node, getArbitraryValue(node.quasis[0].value.raw))
7274
}
7375

74-
const sendReport = (node: any, _value?: string) => {
75-
const value = _value ?? node.value?.toString()
76+
const sendReport = (node: any, value: string) => {
7677
const tkImports = extractTokens(value)
7778
const token = tkImports[0].replace(/^[^.]*\./, '')
7879

plugin/tests/no-important.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function App(){
5252
import { Circle } from './panda/jsx';
5353
5454
function App(){
55-
return <Circle _hover={{ position: 'absolute !' }} />;
55+
return <Circle _hover={{ position: '[absolute!]' }} />;
5656
}`,
5757
},
5858
]

plugin/tests/no-unsafe-token-fn-usage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const styles = css({ bg: token('colors.red.300') })`,
5555
import { Circle } from './panda/jsx';
5656
5757
function App(){
58-
return <Circle margin='{sizes.4}' />;
58+
return <Circle margin='[{sizes.4}]' />;
5959
}`,
6060
},
6161
]

0 commit comments

Comments
 (0)