Skip to content

Commit 44744b7

Browse files
committed
test: add a failing case
1 parent f82cb46 commit 44744b7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/utils/resolve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ function fullResolve(
306306
const sourceFiles =
307307
context.physicalFilename === sourceFile
308308
? [sourceFile]
309-
: [sourceFile, context.physicalFilename]
309+
: [context.physicalFilename, sourceFile]
310310

311311
for (const sourceFile of sourceFiles) {
312312
for (const {
@@ -355,7 +355,7 @@ function fullResolve(
355355
}
356356

357357
// else, counts
358-
fileExistsCache.set(cacheKey, resolved.path as string | null)
358+
fileExistsCache.set(cacheKey, resolved.path)
359359
return resolved
360360
}
361361
}

test/fixtures/config-helper.js

Whitespace-only changes.

test/utils/resolve.spec.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import { setTimeout } from 'node:timers/promises'
66
import { jest } from '@jest/globals'
77
import type { TSESLint } from '@typescript-eslint/utils'
88

9-
import { testContext, testFilePath } from '../utils.js'
9+
import { TEST_FILENAME, testContext, testFilePath } from '../utils.js'
1010

11-
import { importXResolverCompat } from 'eslint-plugin-import-x'
11+
import { cjsRequire, importXResolverCompat } from 'eslint-plugin-import-x'
1212
import type {
1313
CjsRequire,
1414
NewResolver,
1515
NormalizedCacheSettings,
16+
RuleContext,
1617
} from 'eslint-plugin-import-x'
1718
import {
1819
CASE_SENSITIVE_FS,
1920
fileExistsWithCaseSync,
21+
relative,
2022
resolve,
2123
} from 'eslint-plugin-import-x/utils'
2224

@@ -830,5 +832,15 @@ describe('resolve', () => {
830832
}),
831833
).toBe(testFilePath('./bar.tsx'))
832834
})
835+
836+
it('sourceFile should take higher priority than context.physicalFilename', () => {
837+
const sourceFile = cjsRequire.resolve('typescript-eslint')
838+
expect(
839+
relative('./config-helper', sourceFile, {}, {
840+
physicalFilename: TEST_FILENAME,
841+
settings: {},
842+
} as RuleContext),
843+
).toBe(path.resolve(sourceFile, '../config-helper.js'))
844+
})
833845
})
834846
})

0 commit comments

Comments
 (0)