Skip to content

Commit 9219925

Browse files
domenkozarclaude
andcommitted
fix: resolve all clippy warnings
Collapse nested if statements using let chains, replace manual Default impls with derive, use std::slice::from_ref instead of clone, use io::Error::other, remove redundant closures and identity maps, and replace unnecessary lazy evaluation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 65f6bd6 commit 9219925

File tree

9 files changed

+121
-141
lines changed

9 files changed

+121
-141
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

secretspec-derive/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,10 @@ fn is_field_optional_across_profiles(secret_name: &str, config: &Config) -> bool
545545
/// `true` if any profile has this secret with `as_path = true`, `false` otherwise
546546
fn is_field_as_path(secret_name: &str, config: &Config) -> bool {
547547
for profile_config in config.profiles.values() {
548-
if let Some(secret_config) = profile_config.secrets.get(secret_name) {
549-
if secret_config.as_path == Some(true) {
550-
return true;
551-
}
548+
if let Some(secret_config) = profile_config.secrets.get(secret_name)
549+
&& secret_config.as_path == Some(true)
550+
{
551+
return true;
552552
}
553553
}
554554
false

secretspec/src/cli/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,15 @@ pub fn main() -> Result<()> {
402402
ProviderAction::Add { name, uri } => {
403403
// Load or create config
404404
let mut config =
405-
GlobalConfig::load().into_diagnostic()?.unwrap_or_else(|| {
406-
GlobalConfig {
405+
GlobalConfig::load()
406+
.into_diagnostic()?
407+
.unwrap_or(GlobalConfig {
407408
defaults: GlobalDefaults {
408409
provider: None,
409410
profile: None,
410411
providers: None,
411412
},
412-
}
413-
});
413+
});
414414

415415
// Initialize providers map if needed
416416
if config.defaults.providers.is_none() {

secretspec/src/config.rs

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ impl Config {
154154
}
155155

156156
// Process extends if present
157-
if let Some(extends_paths) = config.project.extends.clone() {
158-
if let Some(base) = base_path {
159-
let base_dir = base.parent().unwrap_or(Path::new("."));
160-
config = Self::merge_extended_configs(config, &extends_paths, base_dir, visited)?;
161-
}
157+
if let Some(extends_paths) = config.project.extends.clone()
158+
&& let Some(base) = base_path
159+
{
160+
let base_dir = base.parent().unwrap_or(Path::new("."));
161+
config = Self::merge_extended_configs(config, &extends_paths, base_dir, visited)?;
162162
}
163163

164164
Ok(config)
@@ -447,55 +447,40 @@ impl Secret {
447447
}
448448

449449
// Validate generate config
450-
if let Some(ref gen_config) = self.generate {
451-
if gen_config.is_enabled() {
452-
// generate requires type
453-
if self.secret_type.is_none() {
454-
return Err(
455-
"'generate' requires 'type' to be set (e.g., type = \"password\")".into(),
456-
);
457-
}
450+
if let Some(ref gen_config) = self.generate
451+
&& gen_config.is_enabled()
452+
{
453+
// generate requires type
454+
if self.secret_type.is_none() {
455+
return Err(
456+
"'generate' requires 'type' to be set (e.g., type = \"password\")".into(),
457+
);
458+
}
458459

459-
// generate + default is a conflict
460-
if self.default.is_some() {
461-
return Err("'generate' and 'default' cannot both be set".into());
462-
}
460+
// generate + default is a conflict
461+
if self.default.is_some() {
462+
return Err("'generate' and 'default' cannot both be set".into());
463+
}
463464

464-
// type = "command" requires generate = { command = "..." }
465-
if self.secret_type.as_deref() == Some("command") {
466-
match gen_config {
467-
GenerateConfig::Bool(true) => {
468-
return Err(
469-
"type = \"command\" requires generate = { command = \"...\" }"
470-
.into(),
471-
);
472-
}
473-
GenerateConfig::Options(opts) if opts.command.is_none() => {
474-
return Err(
475-
"type = \"command\" requires generate = { command = \"...\" }"
476-
.into(),
477-
);
478-
}
479-
_ => {}
465+
// type = "command" requires generate = { command = "..." }
466+
if self.secret_type.as_deref() == Some("command") {
467+
match gen_config {
468+
GenerateConfig::Bool(true) => {
469+
return Err(
470+
"type = \"command\" requires generate = { command = \"...\" }".into(),
471+
);
480472
}
481-
}
482-
483-
// Validate known types
484-
if let Some(ref t) = self.secret_type {
485-
match t.as_str() {
486-
"password" | "hex" | "base64" | "uuid" | "command" => {}
487-
unknown => {
488-
return Err(format!("unknown secret type '{}'", unknown));
489-
}
473+
GenerateConfig::Options(opts) if opts.command.is_none() => {
474+
return Err(
475+
"type = \"command\" requires generate = { command = \"...\" }".into(),
476+
);
490477
}
478+
_ => {}
491479
}
492480
}
493-
}
494481

495-
// Validate type even without generate
496-
if let Some(ref t) = self.secret_type {
497-
if self.generate.is_none() || self.generate.as_ref().is_some_and(|g| !g.is_enabled()) {
498-
// Type is informational when not generating, but still validate known values
482+
// Validate known types
483+
if let Some(ref t) = self.secret_type {
499484
match t.as_str() {
500485
"password" | "hex" | "base64" | "uuid" | "command" => {}
501486
unknown => {
@@ -505,6 +490,19 @@ impl Secret {
505490
}
506491
}
507492

493+
// Validate type even without generate
494+
if let Some(ref t) = self.secret_type
495+
&& (self.generate.is_none() || self.generate.as_ref().is_some_and(|g| !g.is_enabled()))
496+
{
497+
// Type is informational when not generating, but still validate known values
498+
match t.as_str() {
499+
"password" | "hex" | "base64" | "uuid" | "command" => {}
500+
unknown => {
501+
return Err(format!("unknown secret type '{}'", unknown));
502+
}
503+
}
504+
}
505+
508506
Ok(())
509507
}
510508
}
@@ -516,10 +514,11 @@ fn is_valid_identifier(s: &str) -> bool {
516514
}
517515

518516
let mut chars = s.chars();
519-
if let Some(first) = chars.next() {
520-
if !first.is_alphabetic() && first != '_' {
521-
return false;
522-
}
517+
if let Some(first) = chars.next()
518+
&& !first.is_alphabetic()
519+
&& first != '_'
520+
{
521+
return false;
523522
}
524523

525524
chars.all(|c| c.is_alphanumeric() || c == '_')

secretspec/src/provider/keyring.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use url::Url;
99
///
1010
/// This struct holds configuration options for the keyring provider,
1111
/// which stores secrets in the system's native keychain service.
12-
#[derive(Debug, Clone, Serialize, Deserialize)]
12+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
1313
pub struct KeyringConfig {
1414
/// Optional folder prefix format string for organizing secrets in the keyring.
1515
///
@@ -18,14 +18,6 @@ pub struct KeyringConfig {
1818
pub folder_prefix: Option<String>,
1919
}
2020

21-
impl Default for KeyringConfig {
22-
fn default() -> Self {
23-
Self {
24-
folder_prefix: None,
25-
}
26-
}
27-
}
28-
2921
impl TryFrom<&Url> for KeyringConfig {
3022
type Error = SecretSpecError;
3123

secretspec/src/provider/onepassword.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,25 @@ impl TryFrom<&Url> for OnePasswordConfig {
147147
let mut config = Self::default();
148148

149149
// Parse URL components for account@vault format, ignoring dummy localhost
150-
if let Some(host) = url.host_str() {
151-
if host != "localhost" {
152-
// Check if we have username (account) information
153-
if !url.username().is_empty() {
154-
// Handle user:token format for service account tokens
155-
if scheme == "onepassword+token" {
156-
if let Some(password) = url.password() {
157-
config.service_account_token = Some(password.to_string());
158-
} else {
159-
config.service_account_token = Some(url.username().to_string());
160-
}
150+
if let Some(host) = url.host_str()
151+
&& host != "localhost"
152+
{
153+
// Check if we have username (account) information
154+
if !url.username().is_empty() {
155+
// Handle user:token format for service account tokens
156+
if scheme == "onepassword+token" {
157+
if let Some(password) = url.password() {
158+
config.service_account_token = Some(password.to_string());
161159
} else {
162-
config.account = Some(url.username().to_string());
160+
config.service_account_token = Some(url.username().to_string());
163161
}
164-
config.default_vault = Some(host.to_string());
165162
} else {
166-
// No username, so the host is the vault
167-
config.default_vault = Some(host.to_string());
163+
config.account = Some(url.username().to_string());
168164
}
165+
config.default_vault = Some(host.to_string());
166+
} else {
167+
// No username, so the host is the vault
168+
config.default_vault = Some(host.to_string());
169169
}
170170
}
171171

@@ -820,24 +820,24 @@ impl Provider for OnePasswordProvider {
820820
if let Ok(item) = serde_json::from_str::<OnePasswordItem>(&stdout) {
821821
// Look for "value" field first
822822
for field in &item.fields {
823-
if field.label.as_deref() == Some("value") {
824-
if let Some(ref v) = field.value {
825-
return Some((
826-
key_owned,
827-
SecretString::new(v.clone().into()),
828-
));
829-
}
823+
if field.label.as_deref() == Some("value")
824+
&& let Some(ref v) = field.value
825+
{
826+
return Some((
827+
key_owned,
828+
SecretString::new(v.clone().into()),
829+
));
830830
}
831831
}
832832
// Fallback: look for password/concealed field
833833
for field in &item.fields {
834-
if field.field_type == "CONCEALED" || field.id == "password" {
835-
if let Some(ref v) = field.value {
836-
return Some((
837-
key_owned,
838-
SecretString::new(v.clone().into()),
839-
));
840-
}
834+
if (field.field_type == "CONCEALED" || field.id == "password")
835+
&& let Some(ref v) = field.value
836+
{
837+
return Some((
838+
key_owned,
839+
SecretString::new(v.clone().into()),
840+
));
841841
}
842842
}
843843
}

secretspec/src/provider/pass.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use url::Url;
1010
/// This struct holds configuration options for the pass provider.
1111
/// Pass stores secrets as GPG-encrypted files using the Unix password
1212
/// manager in a hierarchical structure.
13-
#[derive(Debug, Clone, Serialize, Deserialize)]
13+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
1414
pub struct PassConfig {
1515
/// Optional folder prefix format string for organizing secrets in pass.
1616
///
@@ -19,14 +19,6 @@ pub struct PassConfig {
1919
pub folder_prefix: Option<String>,
2020
}
2121

22-
impl Default for PassConfig {
23-
fn default() -> Self {
24-
Self {
25-
folder_prefix: None,
26-
}
27-
}
28-
}
29-
3022
impl TryFrom<&Url> for PassConfig {
3123
type Error = SecretSpecError;
3224

0 commit comments

Comments
 (0)