Skip to content

Commit ba62e65

Browse files
OliverJAshJounQin
authored andcommitted
fix: remove redundant condition (#69)
* Failing test * Remove redundant condition Fixes #68
1 parent 82ef357 commit ba62e65

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
4343
"test:withJsExtension": "node tests/withJsExtension/test.js && eslint --ext ts,tsx tests/withJsExtension",
4444
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
45+
"test:withPathsAndNestedBaseUrl": "eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",
4546
"test:withQuerystring": "eslint --ext ts,tsx tests/withQuerystring",
4647
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
4748
"type-coverage": "type-coverage --cache --detail --ignore-catch --strict --update"

src/index.ts

+5-14
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function resolve(
6464
}
6565

6666
initMappers(options)
67-
const mappedPath = getMappedPath(source, file)
67+
const mappedPath = getMappedPath(source)
6868
if (mappedPath) {
6969
log('matched ts path:', mappedPath)
7070
}
@@ -153,19 +153,15 @@ function removeJsExtension(id: string) {
153153
}
154154

155155
let mappersBuildForOptions: TsResolverOptions
156-
let mappers:
157-
| Array<(source: string, file: string) => string | undefined>
158-
| undefined
156+
let mappers: Array<(source: string) => string | undefined> | undefined
159157

160158
/**
161159
* @param {string} source the module to resolve; i.e './some-module'
162160
* @param {string} file the importing file's full path; i.e. '/usr/local/bin/file.js'
163161
* @returns The mapped path of the module or undefined
164162
*/
165-
function getMappedPath(source: string, file: string) {
166-
const paths = mappers!
167-
.map(mapper => mapper(source, file))
168-
.filter(path => !!path)
163+
function getMappedPath(source: string) {
164+
const paths = mappers!.map(mapper => mapper(source)).filter(path => !!path)
169165

170166
if (paths.length > 1) {
171167
log('found multiple matching ts paths:', paths)
@@ -230,12 +226,7 @@ function initMappers(options: TsResolverOptions) {
230226
configLoaderResult.paths,
231227
)
232228

233-
return (source: string, file: string) => {
234-
// exclude files that are not part of the config base url
235-
if (!file.includes(configLoaderResult.absoluteBaseUrl)) {
236-
return
237-
}
238-
229+
return (source: string) => {
239230
// look for files based on setup tsconfig "paths"
240231
return matchPath(
241232
source,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../baseEslintConfig')(__dirname)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// import using tsconfig.json `baseUrl`
2+
import 'foo'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// import using tsconfig.json path mapping
2+
import 'other/bar'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "root/",
4+
"paths": {
5+
"other/*": ["../other/*"]
6+
}
7+
},
8+
"files": ["root/foo.ts", "other/bar.ts"]
9+
}

0 commit comments

Comments
 (0)