Skip to content

Commit

Permalink
Fix config file parsing to consider the extends option (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored May 29, 2021
1 parent f2cfca7 commit fc871a1
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 8 deletions.
4 changes: 3 additions & 1 deletion source/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function getOptionsFromTsConfig(cwd: string): CompilerOptions {
return parseJsonSourceFileConfigFileContent(
readJsonConfigFile(configPath, sys.readFile),
sys,
path.basename(configPath)
path.basename(configPath),
undefined,
configPath,
).options;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strict": false
}
}
1 change: 1 addition & 0 deletions source/test/fixtures/ts-config-extends/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (foo: number): number | null;
3 changes: 3 additions & 0 deletions source/test/fixtures/ts-config-extends/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.default = foo => {
return foo > 0 ? foo : null;
};
12 changes: 12 additions & 0 deletions source/test/fixtures/ts-config-extends/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {expectType} from '../../..';
import aboveZero from '.';

expectType<number>(aboveZero(1));

function lookupHeadphonesManufacturer(color: 'blue' | 'black'): string {
if (color === 'blue') {
return 'beats';
} else {
'bose';
}
}
3 changes: 3 additions & 0 deletions source/test/fixtures/ts-config-extends/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "foo"
}
6 changes: 6 additions & 0 deletions source/test/fixtures/ts-config-extends/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./config/base-config",
"compilerOptions": {
"noImplicitReturns": true
}
}
14 changes: 7 additions & 7 deletions source/test/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ type Expectation = [number, number, 'error' | 'warning', string, (string | RegEx
* @param expectations - Expected diagnostics.
*/
export const verify = (t: ExecutionContext, diagnostics: Diagnostic[], expectations: Expectation[]) => {
t.true(diagnostics.length === expectations.length);
t.deepEqual(diagnostics.length, expectations.length, 'Received different count of diagnostics than expected!');

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

const filename = expectations[index][4];

if (typeof filename === 'string') {
t.is(diagnostic.fileName, filename);
t.is(diagnostic.fileName, filename, `"fileName" for diagnostic ${index} doesn't match!`);
} else if (typeof filename === 'object') {
t.regex(diagnostic.fileName, filename);
t.regex(diagnostic.fileName, filename, `"fileName" for diagnostic ${index} doesn't match!`);
}
}
};
8 changes: 8 additions & 0 deletions source/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,11 @@ test('fails if typings file is not found in the specified path', async t => {

t.is(error.message, 'The type definition `unknown.d.ts` does not exist. Create one and try again.');
});

test('includes extended config files along with found ones', async t => {
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/ts-config-extends')});

verify(t, diagnostics, [
[6, 64, 'error', 'Not all code paths return a value.'],
]);
});

0 comments on commit fc871a1

Please sign in to comment.