useGlobalThis
Цей контент ще не доступний вашою мовою.
Summary
Section titled “Summary”- Rule available since:
v2.3.14 - Diagnostic Category:
lint/nursery/useGlobalThis - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
unicorn/prefer-global-this
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useGlobalThis": "error" } } }}Description
Section titled “Description”Enforce the use of globalThis over window, self, and global.
globalThis is a standard way to access the global object across platforms such as browsers, Web Workers, Node.js and so on, and using it can make your code portable.
However, there are several exceptions that are allowed:
- Certain window/Web Workers-specific APIs, such as
window.innerHeightandself.postMessage - Window-specific events, such as
window.addEventListener('resize')
Examples
Section titled “Examples”Invalid
Section titled “Invalid”window.foo;code-block.js:1:1 lint/nursery/useGlobalThis ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Prefer globalThis over window, self and global.
> 1 │ window.foo;
│ ^^^^^^
2 │
ℹ globalThis is the standard way to access the global object across environments, which improves code portability.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
window.addEventListener('click', () => {});code-block.js:1:1 lint/nursery/useGlobalThis ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Prefer globalThis over window, self and global.
> 1 │ window.addEventListener(‘click’, () => {});
│ ^^^^^^
2 │
ℹ globalThis is the standard way to access the global object across environments, which improves code portability.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
globalThis.foo;globalThis.addEventListener('click', () => {});// window/Web Workers-specific APIs are allowedwindow.innerWidth;self.postMessage({ type: 'ready' });// window-specific events are allowedwindow.addEventListener('resize', () => {});Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.