diff --git a/source/lib/formatter.ts b/source/lib/formatter.ts index 3a67c12..9c39327 100644 --- a/source/lib/formatter.ts +++ b/source/lib/formatter.ts @@ -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); } diff --git a/source/test/cli.ts b/source/test/cli.ts index 1f5d510..407fdf6 100644 --- a/source/test/cli.ts +++ b/source/test/cli.ts @@ -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(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', + ]); +}); diff --git a/source/test/fixtures/warnings/only-warnings/index.d.ts b/source/test/fixtures/warnings/only-warnings/index.d.ts new file mode 100644 index 0000000..0616eba --- /dev/null +++ b/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; diff --git a/source/test/fixtures/warnings/only-warnings/index.js b/source/test/fixtures/warnings/only-warnings/index.js new file mode 100644 index 0000000..f17717f --- /dev/null +++ b/source/test/fixtures/warnings/only-warnings/index.js @@ -0,0 +1,3 @@ +module.exports.default = (foo, bar) => { + return foo + bar; +}; diff --git a/source/test/fixtures/warnings/only-warnings/index.test-d.ts b/source/test/fixtures/warnings/only-warnings/index.test-d.ts new file mode 100644 index 0000000..5134757 --- /dev/null +++ b/source/test/fixtures/warnings/only-warnings/index.test-d.ts @@ -0,0 +1,4 @@ +import {printType} from '../../../..'; +import one from '.'; + +printType(one(1, 1)); diff --git a/source/test/fixtures/warnings/only-warnings/package.json b/source/test/fixtures/warnings/only-warnings/package.json new file mode 100644 index 0000000..de6dc1d --- /dev/null +++ b/source/test/fixtures/warnings/only-warnings/package.json @@ -0,0 +1,3 @@ +{ + "name": "foo" +} diff --git a/source/test/fixtures/warnings/with-errors/index.d.ts b/source/test/fixtures/warnings/with-errors/index.d.ts new file mode 100644 index 0000000..0616eba --- /dev/null +++ b/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; diff --git a/source/test/fixtures/warnings/with-errors/index.js b/source/test/fixtures/warnings/with-errors/index.js new file mode 100644 index 0000000..f17717f --- /dev/null +++ b/source/test/fixtures/warnings/with-errors/index.js @@ -0,0 +1,3 @@ +module.exports.default = (foo, bar) => { + return foo + bar; +}; diff --git a/source/test/fixtures/warnings/with-errors/index.test-d.ts b/source/test/fixtures/warnings/with-errors/index.test-d.ts new file mode 100644 index 0000000..65ccce6 --- /dev/null +++ b/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(one(1, 2)); diff --git a/source/test/fixtures/warnings/with-errors/package.json b/source/test/fixtures/warnings/with-errors/package.json new file mode 100644 index 0000000..de6dc1d --- /dev/null +++ b/source/test/fixtures/warnings/with-errors/package.json @@ -0,0 +1,3 @@ +{ + "name": "foo" +}