Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/itchy-poets-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": patch
---

fix: should only use `context.physicalFilename` as fallback instead of main source
2 changes: 1 addition & 1 deletion src/utils/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function fullResolve(
}

// else, counts
fileExistsCache.set(cacheKey, resolved.path as string | null)
fileExistsCache.set(cacheKey, resolved.path)
return resolved
}
}
Expand Down
Empty file added test/fixtures/config-helper.js
Empty file.
16 changes: 14 additions & 2 deletions test/utils/resolve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import { setTimeout } from 'node:timers/promises'
import { jest } from '@jest/globals'
import type { TSESLint } from '@typescript-eslint/utils'

import { testContext, testFilePath } from '../utils.js'
import { TEST_FILENAME, testContext, testFilePath } from '../utils.js'

import { importXResolverCompat } from 'eslint-plugin-import-x'
import { cjsRequire, importXResolverCompat } from 'eslint-plugin-import-x'
import type {
CjsRequire,
NewResolver,
NormalizedCacheSettings,
RuleContext,
} from 'eslint-plugin-import-x'
import {
CASE_SENSITIVE_FS,
fileExistsWithCaseSync,
relative,
resolve,
} from 'eslint-plugin-import-x/utils'

Expand Down Expand Up @@ -830,5 +832,15 @@ describe('resolve', () => {
}),
).toBe(testFilePath('./bar.tsx'))
})

it('sourceFile should take higher priority than context.physicalFilename', () => {
const sourceFile = cjsRequire.resolve('typescript-eslint')
expect(
relative('./config-helper', sourceFile, {}, {
physicalFilename: TEST_FILENAME,
settings: {},
} as RuleContext),
).toBe(path.resolve(sourceFile, '../config-helper.js'))
})
})
})
Loading