summaryrefslogtreecommitdiff
path: root/packages/frontend-shared
diff options
context:
space:
mode:
authortaiy <53635909+taiyme@users.noreply.github.com>2025-09-10 09:22:12 +0900
committerGitHub <noreply@github.com>2025-09-10 09:22:12 +0900
commit7673874675630b68678e1d8603d0f08cd0eece31 (patch)
tree4092a1c7e5f98e22b8e71cd72101e0535c2c5ab9 /packages/frontend-shared
parent[skip ci] Update CHANGELOG.md (prepend template) (diff)
downloadmisskey-7673874675630b68678e1d8603d0f08cd0eece31.tar.gz
misskey-7673874675630b68678e1d8603d0f08cd0eece31.tar.bz2
misskey-7673874675630b68678e1d8603d0f08cd0eece31.zip
fix(eslint): add window prefix rules to frontend-embed & frontend-shared (#16531)
Diffstat (limited to 'packages/frontend-shared')
-rw-r--r--packages/frontend-shared/eslint.config.js68
-rw-r--r--packages/frontend-shared/js/config.ts8
-rw-r--r--packages/frontend-shared/js/scroll.ts10
-rw-r--r--packages/frontend-shared/js/use-document-visibility.ts8
4 files changed, 78 insertions, 16 deletions
diff --git a/packages/frontend-shared/eslint.config.js b/packages/frontend-shared/eslint.config.js
index 6453be0042..b972cfdb27 100644
--- a/packages/frontend-shared/eslint.config.js
+++ b/packages/frontend-shared/eslint.config.js
@@ -51,9 +51,71 @@ export default [
allowSingleExtends: true,
}],
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
- // window の禁止理由: グローバルスコープと衝突し、予期せぬ結果を招くため
- // e の禁止理由: error や event など、複数のキーワードの頭文字であり分かりにくいため
- 'id-denylist': ['error', 'window', 'e'],
+ // window ... グローバルスコープと衝突し、予期せぬ結果を招くため
+ // e ... error や event など、複数のキーワードの頭文字であり分かりにくいため
+ // close ... window.closeと衝突 or 紛らわしい
+ // open ... window.openと衝突 or 紛らわしい
+ // fetch ... window.fetchと衝突 or 紛らわしい
+ // location ... window.locationと衝突 or 紛らわしい
+ // document ... window.documentと衝突 or 紛らわしい
+ // history ... window.historyと衝突 or 紛らわしい
+ // scroll ... window.scrollと衝突 or 紛らわしい
+ // setTimeout ... window.setTimeoutと衝突 or 紛らわしい
+ // setInterval ... window.setIntervalと衝突 or 紛らわしい
+ // clearTimeout ... window.clearTimeoutと衝突 or 紛らわしい
+ // clearInterval ... window.clearIntervalと衝突 or 紛らわしい
+ 'id-denylist': ['error', 'window', 'e', 'close', 'open', 'fetch', 'location', 'document', 'history', 'scroll', 'setTimeout', 'setInterval', 'clearTimeout', 'clearInterval'],
+ 'no-restricted-globals': [
+ 'error',
+ {
+ 'name': 'open',
+ 'message': 'Use `window.open`.',
+ },
+ {
+ 'name': 'close',
+ 'message': 'Use `window.close`.',
+ },
+ {
+ 'name': 'fetch',
+ 'message': 'Use `window.fetch`.',
+ },
+ {
+ 'name': 'location',
+ 'message': 'Use `window.location`.',
+ },
+ {
+ 'name': 'document',
+ 'message': 'Use `window.document`.',
+ },
+ {
+ 'name': 'history',
+ 'message': 'Use `window.history`.',
+ },
+ {
+ 'name': 'scroll',
+ 'message': 'Use `window.scroll`.',
+ },
+ {
+ 'name': 'setTimeout',
+ 'message': 'Use `window.setTimeout`.',
+ },
+ {
+ 'name': 'setInterval',
+ 'message': 'Use `window.setInterval`.',
+ },
+ {
+ 'name': 'clearTimeout',
+ 'message': 'Use `window.clearTimeout`.',
+ },
+ {
+ 'name': 'clearInterval',
+ 'message': 'Use `window.clearInterval`.',
+ },
+ {
+ 'name': 'name',
+ 'message': 'Use `window.name`. もしくは name という変数名を定義し忘れている',
+ },
+ ],
'no-shadow': ['warn'],
'vue/attributes-order': ['error', {
alphabetical: false,
diff --git a/packages/frontend-shared/js/config.ts b/packages/frontend-shared/js/config.ts
index ac5c5629f3..6272d3f6b9 100644
--- a/packages/frontend-shared/js/config.ts
+++ b/packages/frontend-shared/js/config.ts
@@ -4,15 +4,15 @@
*/
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
-const address = new URL(document.querySelector<HTMLMetaElement>('meta[property="instance_url"]')?.content || location.href);
-const siteName = document.querySelector<HTMLMetaElement>('meta[property="og:site_name"]')?.content;
+const address = new URL(window.document.querySelector<HTMLMetaElement>('meta[property="instance_url"]')?.content || window.location.href);
+const siteName = window.document.querySelector<HTMLMetaElement>('meta[property="og:site_name"]')?.content;
export const host = address.host;
export const hostname = address.hostname;
export const url = address.origin;
export const port = address.port;
-export const apiUrl = location.origin + '/api';
-export const wsOrigin = location.origin;
+export const apiUrl = window.location.origin + '/api';
+export const wsOrigin = window.location.origin;
export const lang = localStorage.getItem('lang') ?? 'en-US';
export const langs = _LANGS_;
export const version = _VERSION_;
diff --git a/packages/frontend-shared/js/scroll.ts b/packages/frontend-shared/js/scroll.ts
index 9057b896c6..5578cffdec 100644
--- a/packages/frontend-shared/js/scroll.ts
+++ b/packages/frontend-shared/js/scroll.ts
@@ -51,7 +51,7 @@ export function onScrollTop(el: HTMLElement, cb: (topVisible: boolean) => unknow
// - toleranceの範囲内に収まる程度の微量なスクロールが発生した
let prevTopVisible = firstTopVisible;
const onScroll = () => {
- if (!document.body.contains(el)) return;
+ if (!window.document.body.contains(el)) return;
const topVisible = isHeadVisible(el, tolerance);
if (topVisible !== prevTopVisible) {
@@ -78,7 +78,7 @@ export function onScrollBottom(el: HTMLElement, cb: () => unknown, tolerance = 1
const containerOrWindow = container ?? window;
const onScroll = () => {
- if (!document.body.contains(el)) return;
+ if (!window.document.body.contains(el)) return;
if (isTailVisible(el, 1, container)) {
cb();
if (once) removeListener();
@@ -145,8 +145,8 @@ export function isTailVisible(el: HTMLElement, tolerance = 1, container = getScr
// https://ja.javascript.info/size-and-scroll-window#ref-932
export function getBodyScrollHeight() {
return Math.max(
- document.body.scrollHeight, document.documentElement.scrollHeight,
- document.body.offsetHeight, document.documentElement.offsetHeight,
- document.body.clientHeight, document.documentElement.clientHeight,
+ window.document.body.scrollHeight, window.document.documentElement.scrollHeight,
+ window.document.body.offsetHeight, window.document.documentElement.offsetHeight,
+ window.document.body.clientHeight, window.document.documentElement.clientHeight,
);
}
diff --git a/packages/frontend-shared/js/use-document-visibility.ts b/packages/frontend-shared/js/use-document-visibility.ts
index b1197e68da..a87c1f1bab 100644
--- a/packages/frontend-shared/js/use-document-visibility.ts
+++ b/packages/frontend-shared/js/use-document-visibility.ts
@@ -7,18 +7,18 @@ import { onMounted, onUnmounted, ref } from 'vue';
import type { Ref } from 'vue';
export function useDocumentVisibility(): Ref<DocumentVisibilityState> {
- const visibility = ref(document.visibilityState);
+ const visibility = ref(window.document.visibilityState);
const onChange = (): void => {
- visibility.value = document.visibilityState;
+ visibility.value = window.document.visibilityState;
};
onMounted(() => {
- document.addEventListener('visibilitychange', onChange);
+ window.document.addEventListener('visibilitychange', onChange);
});
onUnmounted(() => {
- document.removeEventListener('visibilitychange', onChange);
+ window.document.removeEventListener('visibilitychange', onChange);
});
return visibility;