API reference for the Scope module: Option-safe variable lookup, reference filtering, scope navigation, and boolean predicates for Effect-first lint rules.
Use this file to discover all available pages before exploring further.
The Scope module provides pure helper functions for analysing lexical scopes, variables, and references inside lint rules. Unlike the SourceCode module, these functions are not effectful — they operate directly on Scope, Variable, and Reference values you already hold. Functions that may return nothing use Option rather than null. Combine them with SourceCode.getScope to walk the scope tree inside any visitor handler.
Searches the scope’s set map for a variable with the given name. Returns Option.some(variable) when found, Option.none() otherwise. Supports both data-first and data-last (pipeable) calling styles.
Like findVariable, but walks up the scope chain through each upper scope until the variable is found or the global scope is exhausted. Returns Option.none() when no scope in the chain declares the variable.
import { Scope } from 'effect-oxlint';import * as Option from 'effect/Option';const result = Scope.findVariableUp(innerScope, 'useEffect');Option.match(result, { onNone: () => console.log('not found in any scope'), onSome: (v) => console.log('found:', v.name)});
Returns the “through” references — identifiers that are referenced inside scope but not resolved there (i.e. they reference bindings in an outer scope or globals).
The Scope functions operate on plain scope objects, so you first obtain the scope via SourceCode.getScope inside a visitor handler, then pass it to the pure Scope helpers:
import { Diagnostic, Rule, Scope, SourceCode } from 'effect-oxlint';import * as Effect from 'effect/Effect';import * as Option from 'effect/Option';const noUnusedImports = Rule.define({ name: 'no-unused-imports', meta: Rule.meta({ type: 'suggestion', description: 'Flag unused import bindings' }), create: function* () { return { ImportDeclaration: (node) => Effect.gen(function* () { const scope = yield* SourceCode.getScope(node); const declared = yield* SourceCode.getDeclaredVariables(node); for (const variable of declared) { if (!Scope.isUsed(variable)) { yield* Effect.log(`Unused import: ${variable.name}`); } } }) }; }});
Use findVariableUp when a visitor handler encounters a reference node and you need to resolve the binding from any enclosing scope. Use findVariable when you already have the exact scope that should declare the name.