Skip to content

Commit 60f072d

Browse files
authored
Update isolated-functions.md
1 parent a52c3ee commit 60f072d

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

docs/rules/isolated-functions.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<!-- end auto-generated rule header -->
66
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->
77

8-
Some functions need to be isolated from their surrounding scope due to execution context constraints. For example, functions passed to `makeSynchronous()` are executed in a subprocess and cannot access variables from outside their scope. This rule helps identify when functions are using external variables that may cause runtime errors.
8+
Some functions need to be isolated from their surrounding scope due to execution context constraints. For example, functions passed to [`makeSynchronous()`](https://github.com/sindresorhus/make-synchronous) are executed in a worker or subprocess and cannot access variables from outside their scope. This rule helps identify when functions are using external variables that may cause runtime errors.
99

1010
Common scenarios where functions must be isolated:
1111

12-
- Functions passed to `makeSynchronous()` (executed in subprocess)
12+
- Functions passed to `makeSynchronous()` (executed in worker)
1313
- Functions that will be serialized via `Function.prototype.toString()`
1414
- Server actions or other remote execution contexts
1515
- Functions with specific JSDoc annotations
@@ -23,10 +23,12 @@ import makeSynchronous from 'make-synchronous';
2323

2424
export const fetchSync = () => {
2525
const url = 'https://example.com';
26+
2627
const getText = makeSynchronous(async () => {
2728
const res = await fetch(url); // ❌ 'url' is not defined in isolated function scope
2829
return res.text();
2930
});
31+
3032
console.log(getText());
3133
};
3234
```
@@ -58,6 +60,7 @@ export const fetchSync = () => {
5860
const res = await fetch(url);
5961
return res.text();
6062
});
63+
6164
console.log(getText());
6265
};
6366
```
@@ -70,6 +73,7 @@ export const fetchSync = () => {
7073
const res = await fetch(url);
7174
return res.text();
7275
});
76+
7377
console.log(getText('https://example.com'));
7478
};
7579
```
@@ -91,6 +95,7 @@ export const fetchSync = () => {
9195
const res = await fetch('https://example.com'); // ✅ Global variables are allowed by default
9296
return res.text();
9397
});
98+
9499
console.log(getText());
95100
};
96101
```
@@ -118,7 +123,9 @@ Array of [ESLint selectors](https://eslint.org/docs/developer-guide/selectors) t
118123
'unicorn/isolated-functions': [
119124
'error',
120125
{
121-
selectors: ['FunctionDeclaration[id.name=/lambdaHandler.*/]']
126+
selectors: [
127+
'FunctionDeclaration[id.name=/lambdaHandler.*/]'
128+
]
122129
}
123130
]
124131
}
@@ -136,7 +143,10 @@ Array of comment strings that mark functions as isolated. Functions with JSDoc c
136143
'unicorn/isolated-functions': [
137144
'error',
138145
{
139-
comments: ['@isolated', '@remote']
146+
comments: [
147+
'@isolated',
148+
'@remote'
149+
]
140150
}
141151
]
142152
}
@@ -173,7 +183,11 @@ Controls how global variables are handled:
173183
'unicorn/isolated-functions': [
174184
'error',
175185
{
176-
functions: ['makeSynchronous', 'createWorker', 'serializeFunction']
186+
functions: [
187+
'makeSynchronous',
188+
'createWorker',
189+
'serializeFunction'
190+
]
177191
}
178192
]
179193
}
@@ -186,7 +200,9 @@ Controls how global variables are handled:
186200
'unicorn/isolated-functions': [
187201
'error',
188202
{
189-
selectors: ['FunctionDeclaration[id.name=/lambdaHandler.*/]']
203+
selectors: [
204+
'FunctionDeclaration[id.name=/lambdaHandler.*/]'
205+
]
190206
}
191207
]
192208
}
@@ -216,7 +232,11 @@ createLambda({
216232
'unicorn/isolated-functions': [
217233
'error',
218234
{
219-
globals: ['console', 'fetch', 'URL']
235+
globals: [
236+
'console',
237+
'fetch',
238+
'URL'
239+
]
220240
}
221241
]
222242
}

0 commit comments

Comments
 (0)