Skip to content

Commit 14af7a3

Browse files
authored
fix: false positive in no-unsafe-token-usage rule (#199)
2 parents cc70de2 + 7e0ee8a commit 14af7a3

File tree

3 files changed

+3576
-2821
lines changed

3 files changed

+3576
-2821
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const rule: Rule = createRule({
6666
})
6767
}
6868

69-
const handleRuntimeFm = (node: TSESTree.Node) => {
69+
const handleRuntimeFn = (node: TSESTree.Node) => {
7070
if (!isCallExpression(node)) return
7171
if (!isUnsafeCallExpression(node)) return
7272

@@ -91,8 +91,9 @@ const rule: Rule = createRule({
9191

9292
const handleTemplateLiteral = (node: TSESTree.Node) => {
9393
if (!isTemplateLiteral(node) || node.expressions.length > 0) return
94-
9594
const value = getArbitraryValue(node.quasis[0].value.raw)
95+
if (isCompositeValue(value)) return
96+
9697
sendReport(node, value)
9798
}
9899

@@ -138,7 +139,7 @@ const rule: Rule = createRule({
138139
const expression = node.value.expression
139140
handleLiteral(expression)
140141
handleTemplateLiteral(expression)
141-
handleRuntimeFm(expression)
142+
handleRuntimeFn(expression)
142143
}
143144
},
144145

@@ -147,8 +148,9 @@ const rule: Rule = createRule({
147148
if (isCachedRecipeVariant(node)) return
148149

149150
const valueNode = node.value
151+
150152
if (isCallExpression(valueNode) || isLiteral(valueNode) || isTemplateLiteral(valueNode)) {
151-
handleRuntimeFm(valueNode)
153+
handleRuntimeFn(valueNode)
152154
handleLiteral(valueNode)
153155
handleTemplateLiteral(valueNode)
154156
}

plugin/tests/_parsing.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ const imports4 = `import { css } from './panda/css';
146146
import { token as tk } from './panda/tokens'
147147
import { Circle } from './panda/jsx';\n\n`
148148

149-
const valids4 = ['const styles = css({ bg: "token(colors.red.300) 50%" })']
149+
const valids4 = [
150+
'const styles = css({ bg: "token(colors.red.300) 50%" })',
151+
'const styles = css({ border: "solid 1px {colors.red.300}" })',
152+
]
150153

151154
const invalids4 = [
152155
{

0 commit comments

Comments
 (0)