diff --git a/README.md b/README.md index 9c64b17..78fc2a1 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Also, check [Danger's guide on Phrasing](http://danger.systems/js/usage/culture. - [ ] Warn when `package.json` was modified and `yarn.lock` or `shrinkwrap` was not - [x] Warn if node version is different between .travis.yml, .nvmrc, package.json and README (or just warn if node version has change just in one of these locations) - [x] At packages.json every package should have its version fixed (do not use ^ or ~), or explicitly set the major and minor versions (ie.: 1.2.x) -- [ ] [TypeScript] Warn if using `` as return type. +- [x] [TypeScript] Warn if using `` as return type. - [x] Warn if some files/folders were changed/committed: - `npm-debug.log` - `yarn-error.log` diff --git a/src/rules/node.test.ts b/src/rules/node.test.ts index 934bede..901b38e 100644 --- a/src/rules/node.test.ts +++ b/src/rules/node.test.ts @@ -102,8 +102,8 @@ describe('Node info', () => { it('Should not warn about `console.log` when it was not added to code', async () => { global.danger = { git: { - modified_files: null, - created_files: null, + modified_files: ['any'], + created_files: ['any'], diffForFile: jest.fn(() => ({ added: ` any text; @@ -114,7 +114,7 @@ describe('Node info', () => { await node.consoleLog(); - expect(global.fail).not.toBeCalled(); + expect(global.warn).not.toBeCalled(); }); }); @@ -333,4 +333,66 @@ describe('Node info', () => { }); + describe('Typescript return any', () => { + + it('Should warn about using as a function return type', async () => { + global.danger = { + git: { + modified_files: ['file.ts'], + created_files: ['any'], + diffForFile: jest.fn(() => ({ + added: ` + test(x): any { + + } + more text`, + })), + }, + }; + + await node.typescriptAnyReturn(); + + expect(global.warn).toBeCalled(); + }); + + it('Should warn about using Promise as a return type', async () => { + global.danger = { + git: { + modified_files: ['file.ts'], + created_files: ['any'], + diffForFile: jest.fn(() => ({ + added: ` + test(x): Promise { + + } + more text`, + })), + }, + }; + + await node.typescriptAnyReturn(); + + expect(global.warn).toBeCalled(); + }); + + it('Should not warn about using as return type', async () => { + global.danger = { + git: { + modified_files: ['file.ts'], + created_files: ['any'], + diffForFile: jest.fn(() => ({ + added: ` + test(x): string { + + } + more text`, + })), + }, + }; + + await node.typescriptAnyReturn(); + + expect(global.warn).not.toBeCalled(); + }); + }); }); diff --git a/src/rules/node.ts b/src/rules/node.ts index de1ad49..b26ab08 100644 --- a/src/rules/node.ts +++ b/src/rules/node.ts @@ -38,7 +38,7 @@ export let node: Scope = { /** Warns when 'console.log' is added to code */ async consoleLog() { - if (changedFilesContainsRegex(/console\.log/ig)) { + if (await changedFilesContainsRegex(/console\.log/ig)) { warn('This PR adds `console.log` to code.'); } }, @@ -127,4 +127,11 @@ export let node: Scope = { } }, + /** Warns when is used as return type */ + async typescriptAnyReturn() { + if (await changedFilesContainsRegex(/\)(\s|\n)*:(\s|\n)*(any|\w+)(\s|\n)*{/g)) { + warn('This PR is using as return type.'); + } + }, + };