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(cli): print number of warnings #184

Merged
merged 10 commits into from
Mar 18, 2023
7 changes: 6 additions & 1 deletion source/lib/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export default (diagnostics: Diagnostic[], showDiff = false): string => {
}
}

entry.errorCount++;
if (diagnostic.severity === 'error') {
entry.errorCount++;
} else if (diagnostic.severity === 'warning') {
entry.warningCount++;
}

entry.messages.push(diagnostic);
}

Expand Down
28 changes: 28 additions & 0 deletions source/test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,31 @@ test('exported formatter matches cli results', async t => {
'1 error',
]);
});

test('warnings are reported correctly and do not fail', async t => {
const {exitCode, stdout} = await execa('../../../../cli.js', {
cwd: path.join(__dirname, 'fixtures/warnings/only-warnings'),
});

t.is(exitCode, 0);
verifyCli(t, stdout, [
'⚠ 4:0 Type for expression one(1, 1) is: number',
'',
'1 warning',
]);
});

test('warnings are reported with errors', async t => {
const {exitCode, stderr} = await t.throwsAsync<ExecaError>(execa('../../../../cli.js', {
cwd: path.join(__dirname, 'fixtures/warnings/with-errors'),
}));

t.is(exitCode, 1);
verifyCli(t, stderr, [
'✖ 5:19 Argument of type number is not assignable to parameter of type string.',
'⚠ 4:0 Type for expression one(1, 1) is: number',
'',
'1 warning',
'1 error',
]);
});
6 changes: 6 additions & 0 deletions source/test/fixtures/warnings/only-warnings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare const one: {
(foo: string, bar: string): string;
(foo: number, bar: number): number;
};

export default one;
3 changes: 3 additions & 0 deletions source/test/fixtures/warnings/only-warnings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.default = (foo, bar) => {
return foo + bar;
};
4 changes: 4 additions & 0 deletions source/test/fixtures/warnings/only-warnings/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {printType} from '../../../..';
import one from '.';

printType(one(1, 1));
3 changes: 3 additions & 0 deletions source/test/fixtures/warnings/only-warnings/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/warnings/with-errors/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare const one: {
(foo: string, bar: string): string;
(foo: number, bar: number): number;
};

export default one;
3 changes: 3 additions & 0 deletions source/test/fixtures/warnings/with-errors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.default = (foo, bar) => {
return foo + bar;
};
5 changes: 5 additions & 0 deletions source/test/fixtures/warnings/with-errors/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {printType, expectType} from '../../../..';
import one from '.';

printType(one(1, 1));
expectType<string>(one(1, 2));
3 changes: 3 additions & 0 deletions source/test/fixtures/warnings/with-errors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "foo"
}