Skip to content

Commit 7aa49ce

Browse files
alphaqiuclaude
andcommitted
fix: address clippy warnings for to_string and map usage
- Implemented Display trait for EnvTag and RiskTag instead of inherent to_string - Changed and_then to map in TagConfigWidget::with_config for better idiomatic Rust - Removed unused enumerate index in passkey_confirm.rs - Changed format! to .to_string() for static strings Note: This only addresses the specific warnings that were causing CI failure. Other pre-existing clippy warnings remain. Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
1 parent 7ac6440 commit 7aa49ce

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

src/tui/screens/passkey_confirm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl PasskeyConfirmScreen {
119119
Style::default().fg(Color::Gray),
120120
)));
121121
let mut first_line = Vec::new();
122-
for (_i, word) in self.passkey_words.iter().take(display_count).enumerate() {
122+
for word in self.passkey_words.iter().take(display_count) {
123123
first_line.push(Span::styled(
124124
format!("{} ", word),
125125
Style::default().fg(Color::Green).add_modifier(Modifier::BOLD),
@@ -131,7 +131,7 @@ impl PasskeyConfirmScreen {
131131

132132
// Last 4 words
133133
summary_lines.push(Line::from(Span::styled(
134-
format!("后 4 词:"),
134+
"后 4 词:".to_string(),
135135
Style::default().fg(Color::Gray),
136136
)));
137137
let mut last_line = Vec::new();

src/tui/tags/config.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use serde::{Deserialize, Serialize};
2+
use std::fmt;
23

34
#[derive(Debug, Clone, Serialize, Deserialize)]
45
pub struct TagConfig {
@@ -31,17 +32,18 @@ pub enum TagError {
3132
InvalidFormat { tag: String, expected: String },
3233
}
3334

34-
impl EnvTag {
35-
pub fn to_string(&self) -> String {
35+
impl fmt::Display for EnvTag {
36+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3637
match self {
37-
Self::Dev => "env:dev",
38-
Self::Test => "env:test",
39-
Self::Staging => "env:staging",
40-
Self::Prod => "env:prod",
38+
Self::Dev => write!(f, "env:dev"),
39+
Self::Test => write!(f, "env:test"),
40+
Self::Staging => write!(f, "env:staging"),
41+
Self::Prod => write!(f, "env:prod"),
4142
}
42-
.to_string()
4343
}
44+
}
4445

46+
impl EnvTag {
4547
pub fn display_name(&self) -> &'static str {
4648
match self {
4749
Self::Dev => "dev (开发环境)",
@@ -61,16 +63,17 @@ impl EnvTag {
6163
}
6264
}
6365

64-
impl RiskTag {
65-
pub fn to_string(&self) -> String {
66+
impl fmt::Display for RiskTag {
67+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6668
match self {
67-
Self::Low => "risk:low",
68-
Self::Medium => "risk:medium",
69-
Self::High => "risk:high",
69+
Self::Low => write!(f, "risk:low"),
70+
Self::Medium => write!(f, "risk:medium"),
71+
Self::High => write!(f, "risk:high"),
7072
}
71-
.to_string()
7273
}
74+
}
7375

76+
impl RiskTag {
7477
pub fn display_name(&self) -> &'static str {
7578
match self {
7679
Self::Low => "low (低风险)",

src/tui/tags/widget.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ impl TagConfigWidget {
7070
/// * `credential_name` - Name of the credential being configured
7171
/// * `config` - Existing tag configuration to load
7272
pub fn with_config(credential_name: String, config: TagConfig) -> Self {
73-
let selected_env = config.env.and_then(|env| match env {
74-
EnvTag::Dev => Some(0),
75-
EnvTag::Test => Some(1),
76-
EnvTag::Staging => Some(2),
77-
EnvTag::Prod => Some(3),
73+
let selected_env = config.env.map(|env| match env {
74+
EnvTag::Dev => 0,
75+
EnvTag::Test => 1,
76+
EnvTag::Staging => 2,
77+
EnvTag::Prod => 3,
7878
});
7979

80-
let selected_risk = config.risk.and_then(|risk| match risk {
81-
RiskTag::Low => Some(0),
82-
RiskTag::Medium => Some(1),
83-
RiskTag::High => Some(2),
80+
let selected_risk = config.risk.map(|risk| match risk {
81+
RiskTag::Low => 0,
82+
RiskTag::Medium => 1,
83+
RiskTag::High => 2,
8484
});
8585

8686
Self {

0 commit comments

Comments
 (0)