Skip to content

Commit 227077c

Browse files
committed
chore: improve performance
1 parent 5ae206f commit 227077c

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

plugin/src/rules/no-config-function-in-source.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isIdentifier, isVariableDeclaration } from '../utils/nodes'
22
import { type Rule, createRule } from '../utils'
3-
import { getAncestor, getImportSpecifiers, isValidFile } from '../utils/helpers'
3+
import { getAncestor, getImportSpecifiers, hasPkgImport, isPandaConfigFunction, isValidFile } from '../utils/helpers'
44

55
export const RULE_NAME = 'no-config-function-in-source'
66

@@ -20,11 +20,14 @@ const rule: Rule = createRule({
2020
},
2121
defaultOptions: [],
2222
create(context) {
23+
if (!hasPkgImport(context)) return {}
24+
2325
return {
2426
CallExpression(node) {
2527
if (!isValidFile(context)) return
2628
if (!isIdentifier(node.callee)) return
2729
if (!CONFIG_FUNCTIONS.includes(node.callee.name)) return
30+
if (!isPandaConfigFunction(context, node.callee.name)) return
2831

2932
context.report({
3033
node,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ const rule: Rule = createRule({
107107
},
108108

109109
Property(node) {
110-
// Ignore css variables
111-
if (isLiteral(node.key) && node.key.value?.toString().startsWith('--')) return
112110
if (!isCallExpression(node.value) && !isLiteral(node.value) && !isTemplateLiteral(node.value)) return
113111
if (!isPandaAttribute(node, context)) return
114112

plugin/src/utils/helpers.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,33 @@ export const getImportSpecifiers = (context: RuleContext<any, any>) => {
4747

4848
node.specifiers.forEach((specifier) => {
4949
if (!isImportSpecifier(specifier)) return
50+
5051
specifiers.push({ specifier, mod })
5152
})
5253
})
5354

5455
return specifiers
5556
}
5657

58+
export const hasPkgImport = (context: RuleContext<any, any>) => {
59+
const imports = _getImports(context)
60+
return imports.some(({ mod }) => mod === '@pandacss/dev')
61+
}
62+
63+
export const isPandaConfigFunction = (context: RuleContext<any, any>, name: string) => {
64+
const imports = _getImports(context)
65+
return imports.some(({ alias, mod }) => alias === name && mod === '@pandacss/dev')
66+
}
67+
5768
const _getImports = (context: RuleContext<any, any>) => {
5869
const specifiers = getImportSpecifiers(context)
59-
specifiers.map(({ specifier, mod }) => ({
70+
71+
const imports: ImportResult[] = specifiers.map(({ specifier, mod }) => ({
6072
name: specifier.imported.name,
6173
alias: specifier.local.name,
6274
mod,
6375
}))
6476

65-
const imports: ImportResult[] = []
66-
67-
context.sourceCode.ast.body.forEach((node) => {
68-
if (!isImportDeclaration(node)) return
69-
70-
const mod = node.source.value
71-
if (!mod) return
72-
73-
node.specifiers.forEach((specifier) => {
74-
if (!isImportSpecifier(specifier)) return
75-
76-
const name = specifier.imported.name
77-
const alias = specifier.local.name
78-
79-
const result = { name, alias, mod }
80-
81-
imports.push(result)
82-
})
83-
})
84-
8577
return imports
8678
}
8779

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ function App(){
2929
return <Circle _hover={{ border: 'solid 1px {colors.blue.400}' }} />;
3030
}`,
3131
},
32-
{
33-
code: javascript`
34-
import { css } from './panda/css';
35-
36-
const styles = css({ '--my-var': '{spacing.8}' })`,
37-
},
3832
]
3933

4034
const invalids = [

0 commit comments

Comments
 (0)