From ba40ad5ce6efc7949f28c2fd3435fad71d841c91 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Thu, 25 Mar 2021 21:03:19 +0100 Subject: [PATCH] chore(clippy): fix new lints (#2507) --- src/config.rs | 20 ++++++++-------- src/context.rs | 2 +- src/formatter/parser.rs | 3 +++ src/modules/git_branch.rs | 8 +++---- src/modules/git_commit.rs | 14 +++++------ src/modules/git_status.rs | 50 +++++++++++++++++++-------------------- src/modules/hg_branch.rs | 12 +++++----- src/modules/kubernetes.rs | 5 +--- src/modules/utils/path.rs | 2 ++ src/test/mod.rs | 8 +++---- 10 files changed, 63 insertions(+), 61 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3b2651e25..f8a0a3a13 100644 --- a/src/config.rs +++ b/src/config.rs @@ -582,15 +582,15 @@ mod tests { #[derive(Debug, PartialEq, Clone)] enum Switch { - ON, - OFF, + On, + Off, } impl<'a> ModuleConfig<'a> for Switch { fn from_config(config: &'a Value) -> Option { match config.as_str()? { - "on" => Some(Self::ON), - "off" => Some(Self::OFF), + "on" => Some(Self::On), + "off" => Some(Self::Off), _ => None, } } @@ -601,15 +601,15 @@ mod tests { switch_b = "any" }; let default_config = TestConfig { - switch_a: Switch::OFF, - switch_b: Switch::OFF, - switch_c: Switch::OFF, + switch_a: Switch::Off, + switch_b: Switch::Off, + switch_c: Switch::Off, }; let rust_config = default_config.load_config(&config); - assert_eq!(rust_config.switch_a, Switch::ON); - assert_eq!(rust_config.switch_b, Switch::OFF); - assert_eq!(rust_config.switch_c, Switch::OFF); + assert_eq!(rust_config.switch_a, Switch::On); + assert_eq!(rust_config.switch_b, Switch::Off); + assert_eq!(rust_config.switch_c, Switch::Off); } #[test] diff --git a/src/context.rs b/src/context.rs index 807f3d183..7abea681b 100644 --- a/src/context.rs +++ b/src/context.rs @@ -332,9 +332,9 @@ impl DirContents { ); Ok(DirContents { - folders, files, file_names, + folders, extensions, }) } diff --git a/src/formatter/parser.rs b/src/formatter/parser.rs index f393cb8be..05158143d 100644 --- a/src/formatter/parser.rs +++ b/src/formatter/parser.rs @@ -1,3 +1,6 @@ +// Can't rename internal Pest names +#![allow(clippy::upper_case_acronyms)] + use pest::{error::Error, iterators::Pair, Parser}; use pest_derive::*; diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs index 6f006e839..0402e1393 100644 --- a/src/modules/git_branch.rs +++ b/src/modules/git_branch.rs @@ -294,7 +294,7 @@ mod tests { #[test] fn test_render_branch_only_attached_on_branch() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; Command::new("git") .args(&["checkout", "-b", "test_branch"]) @@ -322,7 +322,7 @@ mod tests { #[test] fn test_render_branch_only_attached_on_detached() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; Command::new("git") .args(&["checkout", "@~1"]) @@ -394,7 +394,7 @@ mod tests { truncation_symbol: &str, config_options: &str, ) -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; Command::new("git") .args(&["checkout", "-b", branch_name]) @@ -433,7 +433,7 @@ mod tests { config_options: &str, expected: T, ) -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; Command::new("git") .args(&["checkout", "-b", branch_name]) diff --git a/src/modules/git_commit.rs b/src/modules/git_commit.rs index 94b47c8ab..db633ef70 100644 --- a/src/modules/git_commit.rs +++ b/src/modules/git_commit.rs @@ -135,7 +135,7 @@ mod tests { #[test] fn test_render_commit_hash() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_output = Command::new("git") .args(&["rev-parse", "HEAD"]) @@ -167,7 +167,7 @@ mod tests { #[test] fn test_render_commit_hash_len_override() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_output = Command::new("git") .args(&["rev-parse", "HEAD"]) @@ -200,7 +200,7 @@ mod tests { #[test] fn test_render_commit_hash_only_detached_on_branch() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; let actual = ModuleRenderer::new("git_commit") .path(&repo_dir.path()) @@ -214,7 +214,7 @@ mod tests { #[test] fn test_render_commit_hash_only_detached_on_detached() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; Command::new("git") .args(&["checkout", "@~1"]) @@ -247,7 +247,7 @@ mod tests { #[test] fn test_render_commit_hash_with_tag_enabled() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_commit = Command::new("git") .args(&["rev-parse", "HEAD"]) @@ -290,7 +290,7 @@ mod tests { #[test] fn test_render_commit_hash_only_detached_on_detached_with_tag_enabled() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; Command::new("git") .args(&["checkout", "@~1"]) @@ -344,7 +344,7 @@ mod tests { fn test_latest_tag_shown_with_tag_enabled() -> io::Result<()> { use std::{thread, time}; - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; let mut git_commit = Command::new("git") .args(&["rev-parse", "HEAD"]) diff --git a/src/modules/git_status.rs b/src/modules/git_status.rs index e773cdfb5..eaacbb5ec 100644 --- a/src/modules/git_status.rs +++ b/src/modules/git_status.rs @@ -7,7 +7,7 @@ use crate::configs::git_status::GitStatusConfig; use crate::context::Repo; use crate::formatter::StringFormatter; use crate::segment::Segment; -use std::path::PathBuf; +use std::path::Path; use std::sync::Arc; const ALL_STATUS_FORMAT: &str = "$conflicted$stashed$deleted$renamed$modified$staged$untracked"; @@ -183,7 +183,7 @@ impl<'a> GitStatusInfo<'a> { } /// Gets the number of files in various git states (staged, modified, deleted, etc...) -fn get_repo_status(context: &Context, repo_root: &PathBuf) -> Option { +fn get_repo_status(context: &Context, repo_root: &Path) -> Option { log::debug!("New repo status created"); let mut repo_status = RepoStatus::default(); @@ -211,7 +211,7 @@ fn get_repo_status(context: &Context, repo_root: &PathBuf) -> Option Some(repo_status) } -fn get_stashed_count(context: &Context, repo_root: &PathBuf) -> Option { +fn get_stashed_count(context: &Context, repo_root: &Path) -> Option { let stash_output = context.exec_cmd( "git", &[ @@ -359,7 +359,7 @@ mod tests { #[test] fn shows_behind() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; behind(&repo_dir.path())?; @@ -374,7 +374,7 @@ mod tests { #[test] fn shows_behind_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; behind(&repo_dir.path())?; @@ -393,7 +393,7 @@ mod tests { #[test] fn shows_ahead() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; File::create(repo_dir.path().join("readme.md"))?.sync_all()?; ahead(&repo_dir.path())?; @@ -409,7 +409,7 @@ mod tests { #[test] fn shows_ahead_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; File::create(repo_dir.path().join("readme.md"))?.sync_all()?; ahead(&repo_dir.path())?; @@ -429,7 +429,7 @@ mod tests { #[test] fn shows_diverged() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; diverge(&repo_dir.path())?; @@ -444,7 +444,7 @@ mod tests { #[test] fn shows_diverged_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; diverge(&repo_dir.path())?; @@ -463,7 +463,7 @@ mod tests { #[test] fn shows_conflicted() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_conflict(&repo_dir.path())?; @@ -478,7 +478,7 @@ mod tests { #[test] fn shows_conflicted_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_conflict(&repo_dir.path())?; @@ -497,7 +497,7 @@ mod tests { #[test] fn shows_untracked_file() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_untracked(&repo_dir.path())?; @@ -512,7 +512,7 @@ mod tests { #[test] fn shows_untracked_file_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_untracked(&repo_dir.path())?; @@ -531,7 +531,7 @@ mod tests { #[test] fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_untracked(&repo_dir.path())?; @@ -552,7 +552,7 @@ mod tests { #[test] fn shows_stashed() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; barrier(); create_stash(&repo_dir.path())?; @@ -574,7 +574,7 @@ mod tests { #[test] fn shows_stashed_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; barrier(); create_stash(&repo_dir.path())?; @@ -601,7 +601,7 @@ mod tests { #[test] fn shows_modified() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_modified(&repo_dir.path())?; @@ -616,7 +616,7 @@ mod tests { #[test] fn shows_modified_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_modified(&repo_dir.path())?; @@ -635,7 +635,7 @@ mod tests { #[test] fn shows_staged_file() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_staged(&repo_dir.path())?; @@ -650,7 +650,7 @@ mod tests { #[test] fn shows_staged_file_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_staged(&repo_dir.path())?; @@ -676,7 +676,7 @@ mod tests { #[test] fn shows_renamed_file() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_renamed(&repo_dir.path())?; @@ -691,7 +691,7 @@ mod tests { #[test] fn shows_renamed_file_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_renamed(&repo_dir.path())?; @@ -710,7 +710,7 @@ mod tests { #[test] fn shows_deleted_file() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_deleted(&repo_dir.path())?; @@ -725,7 +725,7 @@ mod tests { #[test] fn shows_deleted_file_with_count() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; create_deleted(&repo_dir.path())?; @@ -748,7 +748,7 @@ mod tests { #[test] #[ignore] fn ignore_manually_renamed() -> io::Result<()> { - let repo_dir = fixture_repo(FixtureProvider::GIT)?; + let repo_dir = fixture_repo(FixtureProvider::Git)?; File::create(repo_dir.path().join("a"))?.sync_all()?; File::create(repo_dir.path().join("b"))?.sync_all()?; Command::new("git") diff --git a/src/modules/hg_branch.rs b/src/modules/hg_branch.rs index 6dc54f91e..b0d19edbb 100644 --- a/src/modules/hg_branch.rs +++ b/src/modules/hg_branch.rs @@ -94,7 +94,7 @@ fn get_graphemes(text: &str, length: usize) -> String { } fn graphemes_len(text: &str) -> usize { - UnicodeSegmentation::graphemes(&text[..], true).count() + UnicodeSegmentation::graphemes(text, true).count() } #[cfg(test)] @@ -132,7 +132,7 @@ mod tests { #[test] #[ignore] fn test_hg_disabled_per_default() -> io::Result<()> { - let tempdir = fixture_repo(FixtureProvider::HG)?; + let tempdir = fixture_repo(FixtureProvider::Hg)?; let repo_dir = tempdir.path(); run_hg(&["whatever", "blubber"], &repo_dir)?; expect_hg_branch_with_config( @@ -176,7 +176,7 @@ mod tests { #[test] #[ignore] fn test_hg_bookmark() -> io::Result<()> { - let tempdir = fixture_repo(FixtureProvider::HG)?; + let tempdir = fixture_repo(FixtureProvider::Hg)?; let repo_dir = tempdir.path(); run_hg(&["bookmark", "bookmark-101"], &repo_dir)?; expect_hg_branch_with_config( @@ -190,7 +190,7 @@ mod tests { #[test] #[ignore] fn test_default_truncation_symbol() -> io::Result<()> { - let tempdir = fixture_repo(FixtureProvider::HG)?; + let tempdir = fixture_repo(FixtureProvider::Hg)?; let repo_dir = tempdir.path(); run_hg(&["branch", "-f", "branch-name-101"], &repo_dir)?; run_hg( @@ -218,7 +218,7 @@ mod tests { #[test] #[ignore] fn test_configured_symbols() -> io::Result<()> { - let tempdir = fixture_repo(FixtureProvider::HG)?; + let tempdir = fixture_repo(FixtureProvider::Hg)?; let repo_dir = tempdir.path(); run_hg(&["branch", "-f", "branch-name-121"], &repo_dir)?; run_hg( @@ -252,7 +252,7 @@ mod tests { #[test] #[ignore] fn test_configured_style() -> io::Result<()> { - let tempdir = fixture_repo(FixtureProvider::HG)?; + let tempdir = fixture_repo(FixtureProvider::Hg)?; let repo_dir = tempdir.path(); run_hg(&["branch", "-f", "branch-name-131"], &repo_dir)?; run_hg( diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index c4ff58c75..a71cc1e1a 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -85,10 +85,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { None => Some(Ok(kube_ctx.as_str())), Some(&alias) => Some(Ok(alias)), }, - "namespace" => match &kube_ns { - Some(kube_ns) => Some(Ok(kube_ns)), - None => None, - }, + "namespace" => kube_ns.as_ref().map(|s| Ok(s.as_str())), _ => None, }) .parse(None) diff --git a/src/modules/utils/path.rs b/src/modules/utils/path.rs index 9a22aa110..fb9cbe1d7 100644 --- a/src/modules/utils/path.rs +++ b/src/modules/utils/path.rs @@ -20,6 +20,8 @@ mod normalize { use std::ffi::OsStr; use std::path::{Component, Path, Prefix}; + // allow because this mirrors std + #[allow(clippy::upper_case_acronyms)] #[derive(Debug, PartialEq, Eq)] pub enum NormalizedPrefix<'a> { // No prefix, e.g. `\cat_pics` or `/cat_pics` diff --git a/src/test/mod.rs b/src/test/mod.rs index 0cfab591d..c81d5958b 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -133,13 +133,13 @@ impl<'a> ModuleRenderer<'a> { } pub enum FixtureProvider { - GIT, - HG, + Git, + Hg, } pub fn fixture_repo(provider: FixtureProvider) -> io::Result { match provider { - FixtureProvider::GIT => { + FixtureProvider::Git => { let path = tempfile::tempdir()?; Command::new("git") @@ -166,7 +166,7 @@ pub fn fixture_repo(provider: FixtureProvider) -> io::Result { Ok(path) } - FixtureProvider::HG => { + FixtureProvider::Hg => { let path = tempfile::tempdir()?; Command::new("hg")