Skip to content

Commit de64f8b

Browse files
authored
fix(eslint-plugin): improve search directory resolution for virtual file paths (#4997)
1 parent b554a0e commit de64f8b

File tree

1 file changed

+16
-2
lines changed
  • packages-integrations/eslint-plugin/src

1 file changed

+16
-2
lines changed

packages-integrations/eslint-plugin/src/worker.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ const promises = new Map<string, Promise<UnoGenerator<any>> | undefined>()
1111
// bypass icon rules in ESLint
1212
process.env.ESLINT ||= 'true'
1313

14+
function getSearchCwd(id: string): string {
15+
// Check if it's a virtual file path from ESLint processors
16+
// Virtual paths have the pattern: /path/to/source.ext/virtual_file.ext
17+
// This happens with markdown, MDX, and other files with embedded code blocks
18+
const virtualMatch = id.match(/\.\w+\/[^/]+$/)
19+
20+
if (virtualMatch) {
21+
const realPath = id.slice(0, id.lastIndexOf('/'))
22+
return dirname(realPath)
23+
}
24+
25+
return dirname(id)
26+
}
27+
1428
async function _getGenerator(configPath?: string, id?: string) {
1529
// Determine the search directory:
1630
// 1. If configPath is provided, use process.cwd() (existing behavior for explicit config)
@@ -19,7 +33,7 @@ async function _getGenerator(configPath?: string, id?: string) {
1933
const searchFrom = configPath
2034
? process.cwd()
2135
: id
22-
? dirname(id)
36+
? getSearchCwd(id)
2337
: process.cwd()
2438

2539
const { config, sources } = await loadConfig(
@@ -39,7 +53,7 @@ function getCacheKey(configPath?: string, id?: string): string {
3953
if (configPath)
4054
return `config:${configPath}`
4155
if (id)
42-
return `dir:${dirname(id)}`
56+
return `dir:${getSearchCwd(id)}`
4357
return `cwd:${process.cwd()}`
4458
}
4559

0 commit comments

Comments
 (0)