UNPKG

eslint-plugin-sonarjs

Version:
36 lines (35 loc) • 1.92 kB
import type { Scope } from 'eslint'; import type estree from 'estree'; /** * Returns the nearest enclosing function, module, or global scope. */ export declare function getNearestFunctionScope(scope: Scope.Scope): Scope.Scope; /** * Returns whether a variable is written exactly once in its entire lifetime * (e.g. a `const`, or a `let`/`var` that is never reassigned). Such a binding * has only one possible value once its write executes, so its value can be * trusted from a reader nested inside the write's function scope, as long as * the write also textually precedes the read. */ export declare function hasSingleWrite(variable: Scope.Variable): boolean; /** * Returns whether `scope` is `ancestor` or is nested within it. */ export declare function isDescendantOrSameScope(scope: Scope.Scope, ancestor: Scope.Scope): boolean; /** * Returns a variable's sole write reference before a given identifier use. * Unlike the generic `getUniqueWriteReference` in `helpers/ast.ts` (which finds * a variable's one and only write in its entire lifetime), this also accepts * a `node` to bound the search to writes preceding that specific use, which * this rule's cross-function scope check relies on. */ export declare function getUniqueWriteReferenceBefore(variable: Scope.Variable, node: estree.Identifier): Scope.Reference | undefined; /** * Unwraps TypeScript type assertions (delegating to the shared * `unwrapTypeScriptExpression`, which handles TSAsExpression, TSSatisfiesExpression, * TSTypeAssertion, and TSNonNullExpression) as well as ChainExpression (`x?.property`) * produced by optional chaining; unwrapping it returns the contained optional * MemberExpression (`x?.property`), not its object (`x`). The two kinds of wrapper * can nest in either order, so this alternates between them until neither applies. */ export declare function unwrapTypeAssertion(node: estree.Node): estree.Node;