From 9b43b5588d8da3288cc9e5354da599a086f10fc6 Mon Sep 17 00:00:00 2001 From: anubra266 Date: Thu, 21 Nov 2024 09:41:26 -0800 Subject: [PATCH] Warn when sourceCode is not detected --- .changeset/forty-spiders-warn.md | 5 +++++ plugin/src/utils/helpers.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/forty-spiders-warn.md diff --git a/.changeset/forty-spiders-warn.md b/.changeset/forty-spiders-warn.md new file mode 100644 index 0000000..753a575 --- /dev/null +++ b/.changeset/forty-spiders-warn.md @@ -0,0 +1,5 @@ +--- +'@pandacss/eslint-plugin': patch +--- + +Warn when sourceCode is not detected diff --git a/plugin/src/utils/helpers.ts b/plugin/src/utils/helpers.ts index dd726ba..2f4104a 100644 --- a/plugin/src/utils/helpers.ts +++ b/plugin/src/utils/helpers.ts @@ -101,7 +101,14 @@ export const isPandaIsh = (name: string, context: RuleContext) => { const findDeclaration = (name: string, context: RuleContext) => { try { - const scope = analyze(context.sourceCode.ast, { + const src = context.sourceCode + + if (!src) { + console.warn("⚠️ ESLint's sourceCode is not available. Ensure that the rule is invoked with valid code.") + return undefined + } + + const scope = analyze(src.ast, { sourceType: 'module', }) const decl = scope.variables