diff --git a/.changeset/poor-terms-help.md b/.changeset/poor-terms-help.md new file mode 100644 index 0000000..c4182b9 --- /dev/null +++ b/.changeset/poor-terms-help.md @@ -0,0 +1,5 @@ +--- +"@pandacss/eslint-plugin": patch +--- + +Try catch syncs diff --git a/plugin/src/rules/no-invalid-token-paths.ts b/plugin/src/rules/no-invalid-token-paths.ts index 4ef613f..6274e39 100644 --- a/plugin/src/rules/no-invalid-token-paths.ts +++ b/plugin/src/rules/no-invalid-token-paths.ts @@ -35,6 +35,7 @@ const rule: Rule = createRule({ const sendReport = (node: any, _value?: string) => { const value = _value ?? node.value?.toString() const tokens = getInvalidTokens(value, context) + if (!tokens) return if (tokens.length > 0) { tokens.forEach((token) => { @@ -78,6 +79,7 @@ const rule: Rule = createRule({ const quasis = node.quasi.quasis[0] const styles = quasis.value.raw const tokens = getInvalidTokens(styles, context) + if (!tokens) return tokens.forEach((token, i, arr) => { // Avoid duplicate reports on the same token diff --git a/plugin/src/utils/helpers.ts b/plugin/src/utils/helpers.ts index 80ab345..2a11041 100644 --- a/plugin/src/utils/helpers.ts +++ b/plugin/src/utils/helpers.ts @@ -79,11 +79,7 @@ const _getImports = (context: RuleContext) => { const getImports = (context: RuleContext) => { const imports = _getImports(context) - try { - return imports.filter((imp) => syncAction('matchImports', getSyncOpts(context), imp)) - } catch (error) { - return [] - } + return imports.filter((imp) => syncAction('matchImports', getSyncOpts(context), imp)) } const isValidStyledProp = (node: T, context: RuleContext) => { @@ -156,7 +152,7 @@ export const isPandaProp = (node: TSESTree.JSXAttribute, context: RuleContext, calleeName?: string) => { +export const isStyledProperty = (node: TSESTree.Property, context: RuleContext, calleeName?: string) => { if (!isIdentifier(node.key) && !isLiteral(node.key) && !isTemplateLiteral(node.key)) return if (isIdentifier(node.key) && !isValidProperty(node.key.name, context, calleeName)) return @@ -167,20 +163,9 @@ export const isStyledNode = (node: TSESTree.Property, context: RuleContext, calleeName?: string) => { - const ancestor = node.parent.parent - - const isValidFuncAncestor = - isCallExpression(ancestor) && isIdentifier(ancestor.callee) && isPandaIsh(ancestor.callee.name, context) - if (isValidFuncAncestor) return isStyledNode(node, context, calleeName) - - return isStyledNode(ancestor as any, context, calleeName) && isStyledNode(node, context, calleeName) -} - export const isInPandaFunction = (node: TSESTree.Property, context: RuleContext) => { const callAncestor = getAncestor(isCallExpression, node) if (!callAncestor) return @@ -271,10 +256,6 @@ export const getInvalidTokens = (value: string, context: RuleContext) return syncAction('filterInvalidTokens', getSyncOpts(context), tokens) } -export const getExtendWarnings = (context: RuleContext) => { - return syncAction('getExtendWarnings', getSyncOpts(context)) -} - export const getTokenImport = (context: RuleContext) => { const imports = _getImports(context) return imports.find((imp) => imp.name === 'token') diff --git a/plugin/src/utils/index.ts b/plugin/src/utils/index.ts index 095d5e1..86c1f79 100644 --- a/plugin/src/utils/index.ts +++ b/plugin/src/utils/index.ts @@ -13,7 +13,16 @@ export type Rule = R const isBase = process.env.NODE_ENV !== 'test' || import.meta.url.endsWith('dist/index.js') export const distDir = fileURLToPath(new URL(isBase ? './' : '../../dist', import.meta.url)) -export const syncAction = createSyncFn(join(distDir, 'utils/worker.mjs')) as typeof run +export const _syncAction = createSyncFn(join(distDir, 'utils/worker.mjs')) +// export const _syncAction = createSyncFn(join(distDir, 'utils/worker.mjs')) as typeof run + +export const syncAction = ((...args: any) => { + try { + return _syncAction(...args) + } catch (error) { + return + } +}) as typeof run | ((...args: any) => undefined) export interface ImportResult { name: string diff --git a/plugin/src/utils/worker.ts b/plugin/src/utils/worker.ts index 06d4fd1..e5f22a3 100644 --- a/plugin/src/utils/worker.ts +++ b/plugin/src/utils/worker.ts @@ -31,32 +31,6 @@ export async function getContext(opts: Opts) { } } -async function getExtendWarnings(): Promise { - if (!configPath) return [] - - const cwd = path.dirname(configPath) - const { config } = await bundleConfig({ cwd, file: configPath! }) - - if (!config.presets || config.presets.length === 0) return [] - if (config.eject) return [] - - const warnings = new Set() - - if (config.theme && !config.theme.extend) { - warnings.add('theme') - } - - if (config.conditions && !config.conditions.extend) { - warnings.add('conditions') - } - - if (config.patterns && !config.patterns.extend) { - warnings.add('patterns') - } - - return Array.from(warnings) -} - async function filterInvalidTokens(ctx: PandaContext, paths: string[]): Promise { return paths.filter((path) => !ctx.utility.tokens.view.get(path)) } @@ -137,7 +111,6 @@ type Opts = { configPath?: string } -export function runAsync(action: 'getExtendWarnings', opts: Opts): Promise export function runAsync(action: 'filterInvalidTokens', opts: Opts, paths: string[]): Promise export function runAsync(action: 'isColorToken', opts: Opts, value: string): Promise export function runAsync(action: 'isColorAttribute', opts: Opts, attr: string): Promise @@ -180,12 +153,9 @@ export async function runAsync(action: string, opts: Opts, ...args: any): Promis case 'filterInvalidTokens': // @ts-expect-error cast return filterInvalidTokens(ctx, ...args) - case 'getExtendWarnings': - return getExtendWarnings() } } -export function run(action: 'getExtendWarnings', opts: Opts): string[] export function run(action: 'filterInvalidTokens', opts: Opts, paths: string[]): string[] export function run(action: 'isColorToken', opts: Opts, value: string): boolean export function run(action: 'isColorAttribute', opts: Opts, attr: string): boolean