style: fix clippy warnings and typescript errors

- Add allow(dead_code) for CircuitBreaker::get_state (reserved for future)
- Fix all uninlined format string warnings (27 instances)
- Use inline format syntax for better readability
- Fix unused import and parameter warnings in ProviderActions.tsx
- Achieve zero warnings in both Rust and TypeScript
This commit is contained in:
YoVinchen
2025-12-14 16:05:38 +08:00
parent 4cf4654863
commit 2af8dd2dac
4 changed files with 19 additions and 29 deletions
+1
View File
@@ -202,6 +202,7 @@ impl CircuitBreaker {
}
/// 获取当前状态
#[allow(dead_code)]
pub async fn get_state(&self) -> CircuitState {
*self.state.read().await
}
+2 -2
View File
@@ -34,12 +34,12 @@ impl ProviderRouter {
let current_id = self
.db
.get_current_provider(app_type)?
.ok_or_else(|| AppError::Config(format!("No current provider for {}", app_type)))?;
.ok_or_else(|| AppError::Config(format!("No current provider for {app_type}")))?;
let providers = self.db.get_all_providers(app_type)?;
let provider = providers
.get(&current_id)
.ok_or_else(|| AppError::Config(format!("Current provider {} not found", current_id)))?
.ok_or_else(|| AppError::Config(format!("Current provider {current_id} not found")))?
.clone();
log::info!(
+10 -21
View File
@@ -105,16 +105,12 @@ impl ProxyService {
if let Ok(Some(provider_id)) = self.db.get_current_provider(app_type) {
// 设置为代理目标
if let Err(e) = self.db.set_proxy_target(&provider_id, app_type, true).await {
log::warn!("设置 {} 的代理目标 {} 失败: {}", app_type, provider_id, e);
log::warn!("设置 {app_type} 的代理目标 {provider_id} 失败: {e}");
} else {
log::info!(
"已将 {} 的当前供应商 {} 设置为代理目标",
app_type,
provider_id
);
log::info!("已将 {app_type} 的当前供应商 {provider_id} 设置为代理目标");
}
} else {
log::debug!("{} 没有当前供应商,跳过代理目标设置", app_type);
log::debug!("{app_type} 没有当前供应商,跳过代理目标设置");
}
}
@@ -158,8 +154,7 @@ impl ProxyService {
log::warn!("同步 Claude Token 到数据库失败: {e}");
} else {
log::info!(
"已同步 Claude Token 到数据库 (provider: {})",
provider_id
"已同步 Claude Token 到数据库 (provider: {provider_id})"
);
}
}
@@ -198,8 +193,7 @@ impl ProxyService {
log::warn!("同步 Codex Token 到数据库失败: {e}");
} else {
log::info!(
"已同步 Codex Token 到数据库 (provider: {})",
provider_id
"已同步 Codex Token 到数据库 (provider: {provider_id})"
);
}
}
@@ -238,8 +232,7 @@ impl ProxyService {
log::warn!("同步 Gemini Token 到数据库失败: {e}");
} else {
log::info!(
"已同步 Gemini Token 到数据库 (provider: {})",
provider_id
"已同步 Gemini Token 到数据库 (provider: {provider_id})"
);
}
}
@@ -364,7 +357,7 @@ impl ProxyService {
});
}
self.write_claude_live(&live_config)?;
log::info!("Claude Live 配置已接管,代理地址: {}", proxy_url);
log::info!("Claude Live 配置已接管,代理地址: {proxy_url}");
}
// Codex: 修改 OPENAI_BASE_URL,使用占位符替代真实 Token(代理会注入真实 Token
@@ -375,7 +368,7 @@ impl ProxyService {
auth.insert("OPENAI_API_KEY".to_string(), json!("PROXY_MANAGED"));
}
self.write_codex_live(&live_config)?;
log::info!("Codex Live 配置已接管,代理地址: {}", proxy_url);
log::info!("Codex Live 配置已接管,代理地址: {proxy_url}");
}
// Gemini: 修改 GEMINI_API_BASE,使用占位符替代真实 Token(代理会注入真实 Token
@@ -391,7 +384,7 @@ impl ProxyService {
});
}
self.write_gemini_live(&live_config)?;
log::info!("Gemini Live 配置已接管,代理地址: {}", proxy_url);
log::info!("Gemini Live 配置已接管,代理地址: {proxy_url}");
}
Ok(())
@@ -448,11 +441,7 @@ impl ProxyService {
.set_current_provider(app_type_enum.as_str(), provider_id)
.map_err(|e| format!("更新当前供应商失败: {e}"))?;
log::info!(
"代理模式:已切换 {} 的目标供应商为 {}",
app_type,
provider_id
);
log::info!("代理模式:已切换 {app_type} 的目标供应商为 {provider_id}");
Ok(())
}
+6 -6
View File
@@ -7,7 +7,7 @@ import {
Play,
TestTube2,
Trash2,
RotateCcw,
// RotateCcw, // TODO: 暂时注释,等待故障转移功能启用
} from "lucide-react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
@@ -38,9 +38,9 @@ export function ProviderActions({
onTest,
onConfigureUsage,
onDelete,
onResetCircuitBreaker,
isProxyTarget,
consecutiveFailures = 0,
onResetCircuitBreaker: _onResetCircuitBreaker, // 暂未使用,前缀 _ 避免 lint 警告
isProxyTarget: _isProxyTarget, // 暂未使用,前缀 _ 避免 lint 警告
consecutiveFailures: _consecutiveFailures = 0, // 暂未使用,前缀 _ 避免 lint 警告
}: ProviderActionsProps) {
const { t } = useTranslation();
const iconButtonClass = "h-8 w-8 p-1";
@@ -59,7 +59,7 @@ export function ProviderActions({
// 代理接管模式下启用按钮使用绿色
!isCurrent &&
isProxyTakeover &&
"bg-emerald-500 hover:bg-emerald-600 dark:bg-emerald-600 dark:hover:bg-emerald-700"
"bg-emerald-500 hover:bg-emerald-600 dark:bg-emerald-600 dark:hover:bg-emerald-700",
)}
>
{isCurrent ? (
@@ -158,7 +158,7 @@ export function ProviderActions({
className={cn(
iconButtonClass,
!isCurrent && "hover:text-red-500 dark:hover:text-red-400",
isCurrent && "opacity-40 cursor-not-allowed text-muted-foreground"
isCurrent && "opacity-40 cursor-not-allowed text-muted-foreground",
)}
>
<Trash2 className="h-4 w-4" />