Skip to content

Commit

Permalink
Print number of warnings in the CLI (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Mar 18, 2023
1 parent 223d6a2 commit 3dcaae7
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/lib/formatter.ts
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
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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
{
"name": "foo"
}
6 changes: 6 additions & 0 deletions source/test/fixtures/warnings/with-errors/index.d.ts
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
{
"name": "foo"
}

0 comments on commit 3dcaae7

Please sign in to comment.