Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
check type property and add tests (#4782)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoyopenroot authored and Josh Goldberg committed Jul 4, 2019
1 parent f31dd94 commit 8056e63
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/rules/noAsyncWithoutAwaitRule.ts
Expand Up @@ -69,7 +69,9 @@ function walk(context: Lint.WalkContext) {

const addFailureIfAsyncFunctionHasNoAwait = (node: FunctionNodeType) => {
if (node.body === undefined) {
reportFailureIfAsyncFunction(node);
if (node.type === undefined) {
reportFailureIfAsyncFunction(node);
}
return;
}

Expand Down
67 changes: 55 additions & 12 deletions test/rules/no-async-without-await/test.ts.lint
@@ -1,5 +1,5 @@
async function a(){
~~~~~ [0]
~~~~~ [FAILURE_STRING]
let b = 1;
console.log(b);
}
Expand All @@ -15,15 +15,15 @@ async function a(){
}

async function a(){
~~~~~ [0]
~~~~~ [FAILURE_STRING]
let b = 1;
let c = async () => {
await fetch();
};
}

async function a(){
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
let b = 1;
async function f() {
await fetch();
Expand All @@ -33,20 +33,20 @@ async function a(){
function a(){
let b = 1;
async function f() {
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
fetch();
};
}

const a = async () => {
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
let b = 1;
console.log(b);
}

class A {
async b() {
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
console.log(1);
}
}
Expand All @@ -65,7 +65,7 @@ class A {

class A {
public a = async function b() {
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
b();
}
}
Expand All @@ -78,7 +78,7 @@ class A {

class A {
public a = async () => {
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
b();
}
}
Expand All @@ -91,7 +91,7 @@ async () => {
await a();
class A {
async b() {
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
console.log(1);
}
}
Expand All @@ -105,18 +105,61 @@ async function a() {
let a = async () => 1;

async function a() {
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]
let b = 1;
let a = () => {
return 1;
}
}

async function foo;
~~~~~ [Functions marked async must contain an await or return statement.]
~~~~~ [FAILURE_STRING]

function * foo() {
return 1;
}

[0]: Functions marked async must contain an await or return statement.
abstract class A {
public async func() {
~~~~~ [FAILURE_STRING]
b();
}
}

abstract class A {
public abstract func(): void;
}

abstract class A {
public async func() { /* */ }
~~~~~ [FAILURE_STRING]
}

abstract class A {
public async func(): Promise<number> { /* */ }
~~~~~ [FAILURE_STRING]
}

abstract class A {
public const test: Promise<number>
}

abstract class A {
public abstract async func<T>(param: T): Promise<T>;
}

export async function f(i: number): Promise<void>;
export async function f(s1: string, s2: string): Promise<void>;
export async function f(...args: unknown[]): Promise<void> {
return Promise.resolve();
}

export class A {
public async f(i: number): Promise<void>;
public async f(s1: string, s2: string): Promise<void>;
public async f(..._args: unknown[]): Promise<void> {
return Promise.resolve();
}
}

[FAILURE_STRING]: Functions marked async must contain an await or return statement.

0 comments on commit 8056e63

Please sign in to comment.