Skip to content

Commit

Permalink
fix(eslint-plugin): [promise-function-async] allow any as return value
Browse files Browse the repository at this point in the history
  • Loading branch information
madbence committed May 24, 2019
1 parent cca1714 commit 328ea7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/eslint-plugin/src/rules/promise-function-async.ts
@@ -1,3 +1,5 @@
import ts from 'typescript';
import { isTypeFlagSet } from 'tsutils';
import { TSESTree } from '@typescript-eslint/experimental-utils';
import * as util from '../util';

Expand Down Expand Up @@ -90,6 +92,9 @@ export default util.createRule<Options, MessageIds>({
}
const returnType = checker.getReturnTypeOfSignature(signatures[0]);

if (isTypeFlagSet(returnType, ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
return;
}
if (!util.containsTypeByName(returnType, allAllowedPromiseNames)) {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/eslint-plugin/tests/rules/promise-function-async.test.ts
Expand Up @@ -16,6 +16,16 @@ const ruleTester = new RuleTester({
ruleTester.run('promise-function-async', rule, {
valid: [
`
function returnsAny(): any {
return 1;
}
`,
`
function returnsUnknown(): unknown {
return 1;
}
`,
`
const nonAsyncNonPromiseArrowFunction = (n: number) => n;
`,
`
Expand Down

0 comments on commit 328ea7f

Please sign in to comment.