/
githubmirror
/
eslint-plugin
Обзор
Документация
Войти
/
githubmirror
/
eslint-plugin
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tests/noGlobalThis.test.ts
47 строк
2 KB
Michael Naumov
fix: extract no-global-this
12 май 2026, 12:17
12 май 2026, 12:17
f088476
Код
Авторство
О чём код?
import { RuleTester } from "@typescript-eslint/rule-tester"; import noGlobalThisRule from "../lib/rules/noGlobalThis.js"; const ruleTester = new RuleTester(); ruleTester.run("no-global-this", noGlobalThisRule, { valid: [ { name: "typeof globalThis check is allowed", code: "if (typeof globalThis !== 'undefined') {}", }, { name: "property named global on an object is allowed", code: "const obj = { global: 1 }; obj.global;", }, { name: "declare global is allowed", code: "declare global { var someVar: string; }", }, { name: "local variable named global is allowed", code: "const global = 1; global;", }, { name: "local variable named globalThis is allowed", code: "const globalThis = 1; globalThis;", }, { name: "variable declaration named globalThis is allowed", code: "const globalThis = {};", }, ], invalid: [ { name: "globalThis reference is forbidden", code: "globalThis.setTimeout(() => {}, 100);", output: "window.setTimeout(() => {}, 100);", errors: [{ messageId: "avoidGlobal", data: { name: "globalThis" } }], }, { name: "global reference is forbidden", code: "global.process;", output: "window.process;", errors: [{ messageId: "avoidGlobal", data: { name: "global" } }], }, ], });