Skip to content

Commit

Permalink
Warn when sourceCode is not detected
Browse files Browse the repository at this point in the history
  • Loading branch information
anubra266 committed Nov 21, 2024
1 parent 120f027 commit 9b43b55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/forty-spiders-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pandacss/eslint-plugin': patch
---

Warn when sourceCode is not detected
9 changes: 8 additions & 1 deletion plugin/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ export const isPandaIsh = (name: string, context: RuleContext<any, any>) => {

const findDeclaration = (name: string, context: RuleContext<any, any>) => {
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
Expand Down

0 comments on commit 9b43b55

Please sign in to comment.