import { type TSESLint, TSESTree } from "@typescript-eslint/utils"; import ts from "typescript"; type Context = Readonly>; type Scope = ReturnType; export interface TypeInfo { checker: ts.TypeChecker; toTs(node: TSESTree.Node): ts.Node; } /** The type checker, when the file is linted with type information. */ export declare function getTypeInfo(context: Context): TypeInfo | null; /** * Whether `window` written at `node` would be the global window: * * - no local binding named `window` shadows it, such as a parameter or a * Playwright `const window = await app.firstWindow()`; * - with type information, the program declares it, so the project has the * DOM lib; * - no earlier `typeof window` (or `typeof document`) check says the code * also runs where there is no window, unless it proves the window is there * at `node`; * - `node` is not where a `try` that reads the window goes on when that * throws: its `catch` or `finally`, or the code after it. * * Writing `window` anywhere else is wrong, so a rule offers neither a fix * nor a suggestion there. */ export declare function isGlobalWindowAt(context: Context, node: TSESTree.Node): boolean; /** * Whether code at `node`, where isGlobalWindowAt holds, may still run without * a window as far as the file shows: * * - a condition that decides whether it runs reads a name that says which * environment the code is in, such as `isBrowser`, `env.isNode`, `canUseDOM` * or `typeof process`, from a check that cannot be followed here; * - it is in a `try` whose `catch` drops the error, as in * `try { setTimeout(fn, 0); } catch {}`, where `window` failing would go * unseen; * - the file is Emscripten output, which reads `ENVIRONMENT_IS_WORKER` or * `ENVIRONMENT_IS_NODE` to run in a web worker or in Node as well, and * calls the bare timers outside those checks; * - it is in a function whose source the file turns into a string, as in * `new Blob([`(${body.toString()})()`])` for an inline web worker, where * the code runs without a window. * * A rule offers its rewrite there as a suggestion, not a fix. */ export declare function mayLackWindowAt(context: Context, node: TSESTree.Node): boolean; /** * Whether code at `node` may run where there is no `activeDocument` or * `activeWindow`, as far as the file shows. Those are Obsidian's: a browser * or a DOM emulation such as jsdom has a `document` and a `window` without * them. Code written to run there checks where it is: * * - a window check before it in the same function, or one that decides * whether it runs, whatever the check finds: `typeof document`, * `"window" in globalThis`, a worker check; * - the same for a check of Obsidian's own globals: `typeof activeDocument`, * `"activeWindow" in window`, `window.activeDocument ?? …`, or a bare * `activeDocument` that is only tested; * - the same for a check of one of Obsidian's DOM helpers: * `typeof createDiv === "function"`, `"createEl" in window`; * - it runs where a `try` that reads the window, or calls one of those * helpers by its bare name, has failed, or mayLackWindowAt holds. * * A rule offers no rewrite to `activeDocument` or `activeWindow` there. */ export declare function mayRunOutsideObsidianAt(context: Context, node: TSESTree.Node): boolean; /** The declared type of the global `window`, with type information. */ export declare function getGlobalWindowType(types: TypeInfo, node: TSESTree.Node): ts.Type | null; /** Whether a declaration in the file binds `name` where `scope` can see it. */ export declare function hasLocalBinding(scope: Scope, name: string): boolean; /** Whether the value of `node` is thrown away, so its type cannot matter. */ export declare function isResultDiscarded(node: TSESTree.Expression): boolean; export declare function isDiscardedArrowBody(node: TSESTree.CallExpression, types: TypeInfo | null): boolean; /** * Whether `node` is part of a window check: the `globalThis` in * `typeof globalThis.document`, `"window" in globalThis` or * `!(globalThis as any).window`. As `window`, the check would throw where it * is false. */ export declare function isInWindowCheck(node: TSESTree.Node): boolean; /** * Whether `node`, the global object, is probed for a property that may be * missing: `typeof globalThis.crypto`, `"requestIdleCallback" in globalThis`, * `!globalThis.crypto`, `globalThis.crypto?.randomUUID()`. Such code is * written to work where the property is missing, as in a worker or in Node, * and as `window` it would throw there. */ export declare function isProbeOfGlobal(node: TSESTree.Node): boolean; /** * Whether code at `node` runs only after a probe of the global object, as * isProbeOfGlobal finds it, decides that it runs: * `if (globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();`, * `if (!("crypto" in globalThis)) return; globalThis.crypto.getRandomValues(a);`. * Such code is written for where the property may be missing, and may run * where it is there without a window, as `crypto` is in Node. A rule offers * its rewrite there as a suggestion, as it does for the probe: the code alone * rewritten would no longer read what the probe tests, and TypeScript reports * a probe of a method the code then calls through another path as always * true (TS2774). */ export declare function followsProbeOfGlobal(sourceCode: Context["sourceCode"], node: TSESTree.Node): boolean; /** * Whether TypeScript may have narrowed the global `window` where `node` runs, * to a type without the members `window.x` reads: in the `else` of * `if ("requestIdleCallback" in window)` it is `never`, as Window declares the * property, so `window.setTimeout` there is TS2339. The checks that narrow it * are `"x" in window`, `typeof window` and `window instanceof X`, in the * conditions that decide whether `node` runs (see decidingConditions) in the * same function: TypeScript does not carry the narrowing of a global into a * callback. A check that leaves `window` a Window, as `"x" in window` where * it is true, or `typeof window !== "undefined"`, does not count. */ export declare function windowIsNarrowedAt(sourceCode: Context["sourceCode"], node: TSESTree.Node, types: TypeInfo | null): boolean; /** * Whether `window.(...)` keeps every type a call to Node's or the DOM's * global timer function had. With @types/node, setTimeout() returns a * NodeJS.Timeout and clearTimeout() accepts one, while window's return and * accept a number. */ export declare function isTimerCallTypeSafe(node: TSESTree.CallExpression, name: string, types: TypeInfo | null): boolean; export {};