Skip to content

Commit 86c581e

Browse files
committed
chore: validate diagnostics in examples of Promise-related rules
1 parent 56af34b commit 86c581e

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

crates/biome_analyze/CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,8 @@ The documentation needs to adhere to the following rules:
12111211

12121212
For rules that analyze relationships between multiple files (e.g., import cycles, cross-file dependencies), you can use the `file=<path>` property to create an in-memory file system for testing.
12131213

1214+
This is also useful to trigger type inference even for examples that only consist of individual files.
1215+
12141216
Files are organized by documentation section (Markdown headings), where all files in a section are collected before any tests run. This ensures each test has access to the complete file system regardless of definition order.
12151217

12161218
````rust

crates/biome_js_analyze/src/lint/nursery/no_floating_promises.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ declare_lint_rule! {
3131
///
3232
/// ### Invalid
3333
///
34-
/// ```ts
34+
/// ```ts,expect_diagnostic,file=async-fn.ts
3535
/// async function returnsPromise(): Promise<string> {
3636
/// return 'value';
3737
/// }
3838
/// returnsPromise().then(() => {});
3939
/// ```
4040
///
41-
/// ```ts
41+
/// ```ts,expect_diagnostic,file=async-fn2.ts
4242
/// const returnsPromise = async (): Promise<string> => {
4343
/// return 'value';
4444
/// }
@@ -47,16 +47,16 @@ declare_lint_rule! {
4747
/// }
4848
/// ```
4949
///
50-
/// ```ts
50+
/// ```js,expect_diagnostic,file=new-promise.js
5151
/// const promise = new Promise((resolve) => resolve('value'));
5252
/// promise.then(() => { }).finally(() => { });
5353
/// ```
5454
///
55-
/// ```ts
55+
/// ```js,expect_diagnostic,file=promise-all.js
5656
/// Promise.all([p1, p2, p3])
5757
/// ```
5858
///
59-
/// ```ts
59+
/// ```ts,expect_diagnostic,file=async-method.ts
6060
/// class Api {
6161
/// async returnsPromise(): Promise<string> {
6262
/// return 'value';
@@ -67,7 +67,7 @@ declare_lint_rule! {
6767
/// }
6868
/// ```
6969
///
70-
/// ```ts
70+
/// ```ts,expect_diagnostic,file=async-super-method.ts
7171
/// class Parent {
7272
/// async returnsPromise(): Promise<string> {
7373
/// return 'value';
@@ -81,7 +81,7 @@ declare_lint_rule! {
8181
/// }
8282
/// ```
8383
///
84-
/// ```ts
84+
/// ```ts,expect_diagnostic,file=async-method2.ts
8585
/// class Api {
8686
/// async returnsPromise(): Promise<string> {
8787
/// return 'value';
@@ -91,7 +91,7 @@ declare_lint_rule! {
9191
/// api.returnsPromise().then(() => {}).finally(() => {});
9292
/// ```
9393
///
94-
/// ```ts
94+
/// ```ts,expect_diagnostic,file=async-object-method.ts
9595
/// const obj = {
9696
/// async returnsPromise(): Promise<string> {
9797
/// return 'value';
@@ -101,7 +101,7 @@ declare_lint_rule! {
101101
/// obj.returnsPromise();
102102
/// ```
103103
///
104-
/// ```ts
104+
/// ```ts,expect_diagnostic,file=async-prop.ts
105105
/// type Props = {
106106
/// returnsPromise: () => Promise<void>;
107107
/// };
@@ -113,7 +113,7 @@ declare_lint_rule! {
113113
///
114114
/// ### Valid
115115
///
116-
/// ```ts
116+
/// ```ts,file=valid-examples.ts
117117
/// async function returnsPromise(): Promise<string> {
118118
/// return 'value';
119119
/// }
@@ -141,9 +141,7 @@ declare_lint_rule! {
141141
/// await this.returnsPromise();
142142
/// }
143143
/// }
144-
/// ```
145144
///
146-
/// ```ts
147145
/// type Props = {
148146
/// returnsPromise: () => Promise<void>;
149147
/// };

crates/biome_js_analyze/src/lint/nursery/no_misused_promises.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,34 @@ declare_lint_rule! {
2828
///
2929
/// ### Invalid
3030
///
31-
/// ```js
31+
/// ```js,expect_diagnostic,file=promise-in-condition.js
3232
/// const promise = Promise.resolve('value');
3333
/// if (promise) { /* This branch will always execute */ }
3434
/// ```
3535
///
36-
/// ```js
36+
/// ```js,expect_diagnostic,file=promise-in-ternary-condition.js
3737
/// const promise = Promise.resolve('value');
3838
/// const val = promise ? 123 : 456; // Always evaluates to `123`.
3939
/// ```
4040
///
41-
/// ```js
41+
/// ```js,expect_diagnostic,file=promise-in-filter.js
4242
/// // The following filter has no effect:
4343
/// const promise = Promise.resolve('value');
4444
/// [1, 2, 3].filter(() => promise);
4545
/// ```
4646
///
47-
/// ```js
47+
/// ```js,expect_diagnostic,file=promise-while-condition.js
4848
/// const promise = Promise.resolve('value');
4949
/// while (promise) { /* This is an endless loop */ }
5050
/// ```
5151
///
52-
/// ```js
52+
/// ```js,expect_diagnostic,file=spread-promise.js
5353
/// // Using a `Promise` as an iterable expands to nothing:
5454
/// const getData = () => fetch('/');
5555
/// console.log({ foo: 42, ...getData() });
5656
/// ```
5757
///
58-
/// ```js
58+
/// ```js,expect_diagnostic,file=promise-in-forEach.js
5959
/// // These `fetch`-es are not `await`-ed in order:
6060
/// [1, 2, 3].forEach(async value => {
6161
/// await fetch(`/${value}`);
@@ -64,7 +64,7 @@ declare_lint_rule! {
6464
///
6565
/// ### Valid
6666
///
67-
/// ```js
67+
/// ```js,file=valid-promises.js
6868
/// const promise = Promise.resolve('value');
6969
/// if (await promise) { /* Do something */ }
7070
///

0 commit comments

Comments
 (0)