Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config file parsing to consider the extends option #109

Merged
merged 1 commit into from May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/lib/config.ts
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
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"strict": false
}
}
1 change: 1 addition & 0 deletions source/test/fixtures/ts-config-extends/index.d.ts
@@ -0,0 +1 @@
export default function (foo: number): number | null;
3 changes: 3 additions & 0 deletions source/test/fixtures/ts-config-extends/index.js
@@ -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
@@ -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
@@ -0,0 +1,3 @@
{
"name": "foo"
}
6 changes: 6 additions & 0 deletions source/test/fixtures/ts-config-extends/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "./config/base-config",
"compilerOptions": {
"noImplicitReturns": true
}
}
14 changes: 7 additions & 7 deletions source/test/fixtures/utils.ts
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
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.'],
]);
});