Skip to content

Commit

Permalink
added clippy recommendations, removed unneeded comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mickimnet committed May 21, 2023
1 parent 56c4a45 commit 1375f68
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
8 changes: 8 additions & 0 deletions .github/config-schema.json
Expand Up @@ -783,6 +783,7 @@
},
"hostname": {
"default": {
"detect_env_vars": [],
"disabled": false,
"format": "[$ssh_symbol$hostname]($style) in ",
"ssh_only": true,
Expand Down Expand Up @@ -3693,6 +3694,13 @@
"default": ".",
"type": "string"
},
"detect_env_vars": {
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"format": {
"default": "[$ssh_symbol$hostname]($style) in ",
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion src/configs/hostname.rs
Expand Up @@ -11,7 +11,7 @@ pub struct HostnameConfig<'a> {
pub ssh_only: bool,
pub ssh_symbol: &'a str,
pub trim_at: &'a str,
pub detect_env_vars: Vec<&'a str>,
pub detect_env_vars: Vec<&'a str>,
pub format: &'a str,
pub style: &'a str,
pub disabled: bool,
Expand Down
7 changes: 2 additions & 5 deletions src/context.rs
Expand Up @@ -237,7 +237,7 @@ impl<'a> Context<'a> {

/// Returns true when no negated environment variable is defined in `env_vars`
/// or none of the negated variables is set in the environment.
pub fn has_no_negative_env_vars(&self, env_vars: &'a [&'a str]) -> bool {
fn has_no_negative_env_var(&self, env_vars: &'a [&'a str]) -> bool {
!env_vars
.iter()
.any(|env_var| env_var.starts_with('!') && self.get_env(&env_var[1..]).is_some())
Expand All @@ -246,12 +246,9 @@ impl<'a> Context<'a> {
/// Returns true if 'detect_env_vars' is empty,
/// or if at least one environment variable is set and no negated environment variable is set
pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool {
// old
// env_vars.is_empty() || (env_vars.iter().any(|e| self.get_env(e).is_some()))
// new
env_vars.is_empty()
|| ((env_vars.iter().any(|e| self.get_env(e).is_some()))
&& self.has_no_negative_env_vars(env_vars))
&& self.has_no_negative_env_var(env_vars))
}

// returns a new ScanDir struct with reference to current dir_files of context
Expand Down
4 changes: 1 addition & 3 deletions src/modules/hostname.rs
Expand Up @@ -17,9 +17,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {

let ssh_connection = context.get_env("SSH_CONNECTION");
if config.ssh_only {
if ssh_connection.is_none() {
return None;
}
ssh_connection.as_ref()?;
// check for environment variables
} else if !(context.detect_env_vars(&config.detect_env_vars)) {
return None;
Expand Down

0 comments on commit 1375f68

Please sign in to comment.