Skip to content

Commit

Permalink
test(linter): add class method test cases for oxc/no-async-await (#…
Browse files Browse the repository at this point in the history
…5550)

Adds tests for class and object methods. Diagnostics for the former have incorrect spans.

```javascript
class Foo {
   // span covers `() {}`
  async foo() {}
}
```
  • Loading branch information
DonIsaac committed Sep 8, 2024
1 parent bac03e3 commit 8e79f8d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/oxc_linter/src/rules/oxc/no_async_await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ fn test() {
async test() {}
};
",
// FIXME: diagnostics on method `foo` have incorrect spans
"
class Foo {
async foo() {}
}
",
"
class Foo {
public async foo() {}
}
",
// this one is fine
"
const obj = {
async foo() {}
}
",
];

Tester::new(NoAsyncAwait::NAME, pass, fail).test_and_snapshot();
Expand Down
27 changes: 27 additions & 0 deletions crates/oxc_linter/src/snapshots/no_async_await.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,30 @@ source: crates/oxc_linter/src/tester.rs
4 │ };
╰────
help: Async/await is not allowed

oxc(no-async-await): Unexpected async/await
╭─[no_async_await.tsx:3:22]
2class Foo {
3async foo() {}
· ─────
4 │ }
╰────
help: Async/await is not allowed

oxc(no-async-await): Unexpected async/await
╭─[no_async_await.tsx:3:29]
2class Foo {
3public async foo() {}
· ─────
4 │ }
╰────
help: Async/await is not allowed

oxc(no-async-await): Unexpected async/await
╭─[no_async_await.tsx:3:13]
2const obj = {
3 │ async foo() {}
· ─────
4 │ }
╰────
help: Async/await is not allowed

0 comments on commit 8e79f8d

Please sign in to comment.