Skip to content

Commit fc871a1

Browse files
Fix config file parsing to consider the extends option (#109)
1 parent f2cfca7 commit fc871a1

File tree

9 files changed

+48
-8
lines changed

9 files changed

+48
-8
lines changed

source/lib/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ function getOptionsFromTsConfig(cwd: string): CompilerOptions {
5656
return parseJsonSourceFileConfigFileContent(
5757
readJsonConfigFile(configPath, sys.readFile),
5858
sys,
59-
path.basename(configPath)
59+
path.basename(configPath),
60+
undefined,
61+
configPath,
6062
).options;
6163
}
6264

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"strict": false
4+
}
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function (foo: number): number | null;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports.default = foo => {
2+
return foo > 0 ? foo : null;
3+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {expectType} from '../../..';
2+
import aboveZero from '.';
3+
4+
expectType<number>(aboveZero(1));
5+
6+
function lookupHeadphonesManufacturer(color: 'blue' | 'black'): string {
7+
if (color === 'blue') {
8+
return 'beats';
9+
} else {
10+
'bose';
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "foo"
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./config/base-config",
3+
"compilerOptions": {
4+
"noImplicitReturns": true
5+
}
6+
}

source/test/fixtures/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ type Expectation = [number, number, 'error' | 'warning', string, (string | RegEx
1111
* @param expectations - Expected diagnostics.
1212
*/
1313
export const verify = (t: ExecutionContext, diagnostics: Diagnostic[], expectations: Expectation[]) => {
14-
t.true(diagnostics.length === expectations.length);
14+
t.deepEqual(diagnostics.length, expectations.length, 'Received different count of diagnostics than expected!');
1515

1616
for (const [index, diagnostic] of diagnostics.entries()) {
17-
t.is(diagnostic.line, expectations[index][0]);
18-
t.is(diagnostic.column, expectations[index][1]);
19-
t.is(diagnostic.severity, expectations[index][2]);
20-
t.is(diagnostic.message, expectations[index][3]);
17+
t.is(diagnostic.line, expectations[index][0], `"line" for diagnostic ${index} doesn't match!`);
18+
t.is(diagnostic.column, expectations[index][1], `"column" for diagnostic ${index} doesn't match!`);
19+
t.is(diagnostic.severity, expectations[index][2], `"severity" for diagnostic ${index} doesn't match!`);
20+
t.is(diagnostic.message, expectations[index][3], `"message" for diagnostic ${index} doesn't match!`);
2121

2222
const filename = expectations[index][4];
2323

2424
if (typeof filename === 'string') {
25-
t.is(diagnostic.fileName, filename);
25+
t.is(diagnostic.fileName, filename, `"fileName" for diagnostic ${index} doesn't match!`);
2626
} else if (typeof filename === 'object') {
27-
t.regex(diagnostic.fileName, filename);
27+
t.regex(diagnostic.fileName, filename, `"fileName" for diagnostic ${index} doesn't match!`);
2828
}
2929
}
3030
};

source/test/test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,11 @@ test('fails if typings file is not found in the specified path', async t => {
305305

306306
t.is(error.message, 'The type definition `unknown.d.ts` does not exist. Create one and try again.');
307307
});
308+
309+
test('includes extended config files along with found ones', async t => {
310+
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/ts-config-extends')});
311+
312+
verify(t, diagnostics, [
313+
[6, 64, 'error', 'Not all code paths return a value.'],
314+
]);
315+
});

0 commit comments

Comments
 (0)