Skip to content

Commit

Permalink
fix: false positive in no-unsafe-token-usage rule (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 authored Dec 27, 2024
2 parents cc70de2 + 7e0ee8a commit 14af7a3
Show file tree
Hide file tree
Showing 3 changed files with 3,576 additions and 2,821 deletions.
10 changes: 6 additions & 4 deletions plugin/src/rules/no-unsafe-token-fn-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const rule: Rule = createRule({
})
}

const handleRuntimeFm = (node: TSESTree.Node) => {
const handleRuntimeFn = (node: TSESTree.Node) => {
if (!isCallExpression(node)) return
if (!isUnsafeCallExpression(node)) return

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

const handleTemplateLiteral = (node: TSESTree.Node) => {
if (!isTemplateLiteral(node) || node.expressions.length > 0) return

const value = getArbitraryValue(node.quasis[0].value.raw)
if (isCompositeValue(value)) return

sendReport(node, value)
}

Expand Down Expand Up @@ -138,7 +139,7 @@ const rule: Rule = createRule({
const expression = node.value.expression
handleLiteral(expression)
handleTemplateLiteral(expression)
handleRuntimeFm(expression)
handleRuntimeFn(expression)
}
},

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

const valueNode = node.value

if (isCallExpression(valueNode) || isLiteral(valueNode) || isTemplateLiteral(valueNode)) {
handleRuntimeFm(valueNode)
handleRuntimeFn(valueNode)
handleLiteral(valueNode)
handleTemplateLiteral(valueNode)
}
Expand Down
5 changes: 4 additions & 1 deletion plugin/tests/_parsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ const imports4 = `import { css } from './panda/css';
import { token as tk } from './panda/tokens'
import { Circle } from './panda/jsx';\n\n`

const valids4 = ['const styles = css({ bg: "token(colors.red.300) 50%" })']
const valids4 = [
'const styles = css({ bg: "token(colors.red.300) 50%" })',
'const styles = css({ border: "solid 1px {colors.red.300}" })',
]

const invalids4 = [
{
Expand Down
Loading

0 comments on commit 14af7a3

Please sign in to comment.