Skip to content

Commit b3649e9

Browse files
committed
docs: group fail/pass examples closer
1 parent 7786865 commit b3649e9

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

docs/rules/isolated-functions.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Common scenarios where functions must be isolated:
1616

1717
By default, this rule allows global variables (like `console`, `fetch`, etc.) in isolated functions, but prevents usage of variables from the surrounding scope.
1818

19-
## Fail
19+
## Examples
2020

2121
```js
2222
import makeSynchronous from 'make-synchronous';
@@ -31,45 +31,36 @@ export const fetchSync = () => {
3131

3232
console.log(getText());
3333
};
34-
```
3534

36-
```js
37-
const foo = 'hi';
38-
39-
/** @isolated */
40-
function abc() {
41-
return foo.slice(); // ❌ 'foo' is not defined in isolated function scope
42-
}
43-
```
44-
45-
```js
46-
const foo = 'hi';
35+
//
36+
export const fetchSync = () => {
37+
const getText = makeSynchronous(async () => {
38+
const url = 'https://example.com'; // Variable defined within function scope
39+
const res = await fetch(url);
40+
return res.text();
41+
});
4742

48-
/** @isolated */
49-
const abc = () => foo.slice(); // ❌ 'foo' is not defined in isolated function scope
43+
console.log(getText());
44+
};
5045
```
5146

52-
## Pass
53-
5447
```js
5548
import makeSynchronous from 'make-synchronous';
5649

5750
export const fetchSync = () => {
51+
const url = 'https://example.com';
52+
5853
const getText = makeSynchronous(async () => {
59-
const url = 'https://example.com'; // ✅ Variable defined within function scope
60-
const res = await fetch(url);
54+
const res = await fetch(url); // ❌ 'url' is not defined in isolated function scope
6155
return res.text();
6256
});
6357

6458
console.log(getText());
6559
};
66-
```
67-
68-
```js
69-
import makeSynchronous from 'make-synchronous';
7060

61+
//
7162
export const fetchSync = () => {
72-
const getText = makeSynchronous(async (url) => { // Variable passed as parameter
63+
const getText = makeSynchronous(async (url) => { // Variable passed as parameter
7364
const res = await fetch(url);
7465
return res.text();
7566
});
@@ -79,13 +70,35 @@ export const fetchSync = () => {
7970
```
8071

8172
```js
73+
const foo = 'hi';
74+
75+
/** @isolated */
76+
function abc() {
77+
return foo.slice(); // ❌ 'foo' is not defined in isolated function scope
78+
}
79+
80+
//
8281
/** @isolated */
8382
function abc() {
84-
const foo = 'hi'; // Variable defined within function scope
83+
const foo = 'hi'; // Variable defined within function scope
8584
return foo.slice();
8685
}
8786
```
8887

88+
```js
89+
const foo = 'hi';
90+
91+
/** @isolated */
92+
const abc = () => foo.slice(); // ❌ 'foo' is not defined in isolated function scope
93+
94+
//
95+
/** @isolated */
96+
const abc = () => {
97+
const foo = 'hi'; // Variable defined within function scope
98+
return foo.slice();
99+
};
100+
```
101+
89102
```js
90103
import makeSynchronous from 'make-synchronous';
91104

0 commit comments

Comments
 (0)