Skip to content

Commit 70c0510

Browse files
committed
Address PR feedback
1 parent a316041 commit 70c0510

File tree

6 files changed

+43
-58
lines changed

6 files changed

+43
-58
lines changed

Diff for: src/ExportMap.js

+27-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import path from 'path';
2+
import { dirname } from 'path';
33

44
import doctrine from 'doctrine';
55

@@ -517,6 +517,32 @@ ExportMap.parse = function (path, content, context) {
517517

518518
const source = makeSourceCode(content, ast);
519519

520+
function readTsConfig() {
521+
const tsConfigInfo = tsConfigLoader({
522+
cwd:
523+
(context.parserOptions && context.parserOptions.tsconfigRootDir) ||
524+
process.cwd(),
525+
getEnv: (key) => process.env[key],
526+
});
527+
try {
528+
if (tsConfigInfo.tsConfigPath !== undefined) {
529+
// Projects not using TypeScript won't have `typescript` installed.
530+
if (!ts) (ts = require('typescript'));
531+
532+
const configFile = ts.readConfigFile(tsConfigInfo.tsConfigPath, ts.sys.readFile);
533+
return ts.parseJsonConfigFileContent(
534+
configFile.config,
535+
ts.sys,
536+
dirname(tsConfigInfo.tsConfigPath),
537+
);
538+
}
539+
} catch (e) {
540+
// Catch any errors
541+
}
542+
543+
return null;
544+
}
545+
520546
function isEsModuleInterop() {
521547
const cacheKey = hashObject({
522548
tsconfigRootDir: context.parserOptions && context.parserOptions.tsconfigRootDir,
@@ -763,32 +789,3 @@ function makeSourceCode(text, ast) {
763789
return new SourceCode({ text, ast });
764790
}
765791
}
766-
767-
/**
768-
* Returns a project's TypeScript configuration.
769-
*/
770-
export function readTsConfig(context) {
771-
const tsConfigInfo = tsConfigLoader({
772-
cwd:
773-
(context.parserOptions && context.parserOptions.tsconfigRootDir) ||
774-
process.cwd(),
775-
getEnv: (key) => process.env[key],
776-
});
777-
try {
778-
if (tsConfigInfo.tsConfigPath !== undefined) {
779-
// Projects not using TypeScript won't have `typescript` installed.
780-
if (!ts) (ts = require('typescript'));
781-
782-
const configFile = ts.readConfigFile(tsConfigInfo.tsConfigPath, ts.sys.readFile);
783-
return ts.parseJsonConfigFileContent(
784-
configFile.config,
785-
ts.sys,
786-
path.dirname(tsConfigInfo.tsConfigPath),
787-
);
788-
}
789-
} catch (e) {
790-
// Catch any errors
791-
}
792-
793-
return null;
794-
}

Diff for: tests/files/typescript-extended-config/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export = FooBar;
2+
3+
declare namespace FooBar {}
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"compilerOptions": {
3-
"esModuleInterop": true,
4-
"forceConsistentCasingInFileNames": true,
5-
"skipLibCheck": true,
6-
"strict": true
3+
"esModuleInterop": true
74
}
85
}

Diff for: tests/files/typescript-extended-config/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
22
"extends": "./tsconfig.base.json",
3-
"compilerOptions": {
4-
"noEmit": true
5-
}
3+
"compilerOptions": {}
64
}

Diff for: tests/src/ExportMap.js

-21
This file was deleted.

Diff for: tests/src/rules/default.js

+11
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ context('TypeScript', function () {
231231
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-export-react-test-renderer/'),
232232
},
233233
}),
234+
test({
235+
code: `import Foo from "./typescript-extended-config"`,
236+
parser,
237+
settings: {
238+
'import/parsers': { [parser]: ['.ts'] },
239+
'import/resolver': { 'eslint-import-resolver-typescript': true },
240+
},
241+
parserOptions: {
242+
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-extended-config/'),
243+
},
244+
}),
234245
test({
235246
code: `import foobar from "./typescript-export-assign-property"`,
236247
parser,

0 commit comments

Comments
 (0)