chore(frontend): introduce prettier + eslint and prune unused code
Backend CI / Backend (push) Has been cancelled
Frontend CI / Frontend (push) Failing after 1m39s

- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports)
- Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier
- Add root scripts: format, format:check, lint, lint:fix
- Reformat 257 files across admin-web, ops-web, desktop-client, packages
- Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters
- Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex
- Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-01 20:39:09 +08:00
parent 21c7892ee4
commit 162abdc97c
258 changed files with 42261 additions and 37556 deletions
+50 -50
View File
@@ -1,24 +1,24 @@
import type { BrowserWindow } from "electron/main";
import type { BrowserWindow } from 'electron/main'
import { STANDARD_USER_AGENT } from "./user-agent";
import { STANDARD_USER_AGENT } from './user-agent'
const ignoredNavigationFailurePattern = /ERR_ABORTED|ERR_BLOCKED_BY_CLIENT/i;
const errorPagePrefix = "data:text/html";
const ignoredNavigationFailurePattern = /ERR_ABORTED|ERR_BLOCKED_BY_CLIENT/i
const errorPagePrefix = 'data:text/html'
interface WindowNavigationState {
readyForDetection: boolean;
lastMainFrameError: string | null;
readyForDetection: boolean
lastMainFrameError: string | null
}
const navigationStateRegistry = new WeakMap<BrowserWindow, WindowNavigationState>();
const navigationStateRegistry = new WeakMap<BrowserWindow, WindowNavigationState>()
function escapeHtml(value: string): string {
return value
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll("\"", "&quot;")
.replaceAll("'", "&#39;");
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#39;')
}
function errorPageDataURL(context: string, targetURL: string, message: string): string {
@@ -117,75 +117,75 @@ ${escapeHtml(targetURL)}</pre>
</div>
</main>
</body>
</html>`;
</html>`
return `data:text/html;charset=UTF-8,${encodeURIComponent(html)}`;
return `data:text/html;charset=UTF-8,${encodeURIComponent(html)}`
}
export function attachWindowDiagnostics(window: BrowserWindow, context: string): void {
navigationStateRegistry.set(window, {
readyForDetection: false,
lastMainFrameError: null,
});
})
window.webContents.on("did-start-loading", () => {
const state = navigationStateRegistry.get(window);
window.webContents.on('did-start-loading', () => {
const state = navigationStateRegistry.get(window)
if (!state) {
return;
return
}
state.readyForDetection = false;
});
state.readyForDetection = false
})
window.webContents.on(
"did-fail-load",
'did-fail-load',
(_event, errorCode, errorDescription, validatedURL, isMainFrame) => {
if (!isMainFrame || errorCode === -3) {
return;
return
}
const state = navigationStateRegistry.get(window);
const state = navigationStateRegistry.get(window)
if (state) {
state.readyForDetection = false;
state.lastMainFrameError = `${errorCode}:${errorDescription}`;
state.readyForDetection = false
state.lastMainFrameError = `${errorCode}:${errorDescription}`
}
console.warn(`[desktop-window] ${context} main-frame load failed`, {
errorCode,
errorDescription,
validatedURL,
});
})
},
);
)
window.webContents.on("did-finish-load", () => {
const state = navigationStateRegistry.get(window);
window.webContents.on('did-finish-load', () => {
const state = navigationStateRegistry.get(window)
if (!state) {
return;
return
}
const currentURL = window.webContents.getURL();
state.readyForDetection = !currentURL.startsWith(errorPagePrefix);
const currentURL = window.webContents.getURL()
state.readyForDetection = !currentURL.startsWith(errorPagePrefix)
if (state.readyForDetection) {
state.lastMainFrameError = null;
state.lastMainFrameError = null
}
});
})
window.webContents.on("render-process-gone", (_event, details) => {
const state = navigationStateRegistry.get(window);
window.webContents.on('render-process-gone', (_event, details) => {
const state = navigationStateRegistry.get(window)
if (state) {
state.readyForDetection = false;
state.readyForDetection = false
}
console.error(`[desktop-window] ${context} renderer gone`, details);
});
console.error(`[desktop-window] ${context} renderer gone`, details)
})
}
export function isWindowReadyForDetection(window: BrowserWindow): boolean {
const state = navigationStateRegistry.get(window);
const state = navigationStateRegistry.get(window)
if (!state) {
return !window.webContents.getURL().startsWith(errorPagePrefix);
return !window.webContents.getURL().startsWith(errorPagePrefix)
}
return state.readyForDetection;
return state.readyForDetection
}
export async function loadWindowURLSafely(
@@ -194,32 +194,32 @@ export async function loadWindowURLSafely(
context: string,
): Promise<void> {
try {
await window.loadURL(targetURL, { userAgent: STANDARD_USER_AGENT });
await window.loadURL(targetURL, { userAgent: STANDARD_USER_AGENT })
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
const message = error instanceof Error ? error.message : String(error)
if (ignoredNavigationFailurePattern.test(message) || window.isDestroyed()) {
return;
return
}
console.error(`[desktop-window] ${context} loadURL failed`, {
targetURL,
message,
});
})
if (window.webContents.getURL().startsWith(errorPagePrefix)) {
return;
return
}
try {
await window.loadURL(errorPageDataURL(context, targetURL, message));
await window.loadURL(errorPageDataURL(context, targetURL, message))
} catch (fallbackError) {
const fallbackMessage =
fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
fallbackError instanceof Error ? fallbackError.message : String(fallbackError)
console.error(`[desktop-window] ${context} error-page loadURL failed`, {
targetURL,
message: fallbackMessage,
});
})
}
}
}