Skip to content

Isolated Functions

Error
small-rules/isolated-functions

Prevent usage of variables from outside the scope of isolated functions.

Diagnostic Messages

externallyScopedVariable
Variable {{name}} not defined in scope of isolated function. Function is isolated because: {{reason}}.
super
Unexpected `super` in isolated function. Function is isolated because: {{reason}}.
thisExpression
Unexpected `this` in isolated function. Function is isolated because: {{reason}}.

Configuration

This rule accepts one options object after the severity.

commentsOptional

Comment patterns that mark a function as isolated.

functionsOptional

Function names that mark argument callbacks as isolated.

overrideGlobalsOptional

Override which global variables are allowed inside isolated scopes.

selectorsOptional

AST selectors that mark matched function nodes as isolated.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/isolated-functions": [
"error",
{
"comments": [
"value"
],
"functions": [
"value"
],
"overrideGlobals": {},
"selectors": [
"value"
]
}
]
}
}

Examples

Outer variable in isolated callback
const foo = 'hi';
makeSynchronous(() => {
return foo.slice();
});
Locals defined inside isolated callback
makeSynchronous(() => {
const foo = 'hi';
return foo.slice();
});