Skip to content

Commit 9b43b55

Browse files
committed
Warn when sourceCode is not detected
1 parent 120f027 commit 9b43b55

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/forty-spiders-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@pandacss/eslint-plugin': patch
3+
---
4+
5+
Warn when sourceCode is not detected

plugin/src/utils/helpers.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ export const isPandaIsh = (name: string, context: RuleContext<any, any>) => {
101101

102102
const findDeclaration = (name: string, context: RuleContext<any, any>) => {
103103
try {
104-
const scope = analyze(context.sourceCode.ast, {
104+
const src = context.sourceCode
105+
106+
if (!src) {
107+
console.warn("⚠️ ESLint's sourceCode is not available. Ensure that the rule is invoked with valid code.")
108+
return undefined
109+
}
110+
111+
const scope = analyze(src.ast, {
105112
sourceType: 'module',
106113
})
107114
const decl = scope.variables

0 commit comments

Comments
 (0)