chore(clippy): fix new lints (#2507)

This commit is contained in:
David Knaack 2021-03-25 21:03:19 +01:00 committed by GitHub
parent 28f7416a6e
commit ba40ad5ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 63 additions and 61 deletions

View File

@ -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<Self> {
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]

View File

@ -332,9 +332,9 @@ impl DirContents {
);
Ok(DirContents {
folders,
files,
file_names,
folders,
extensions,
})
}

View File

@ -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::*;

View File

@ -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])

View File

@ -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"])

View File

@ -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<RepoStatus> {
fn get_repo_status(context: &Context, repo_root: &Path) -> Option<RepoStatus> {
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<RepoStatus>
Some(repo_status)
}
fn get_stashed_count(context: &Context, repo_root: &PathBuf) -> Option<usize> {
fn get_stashed_count(context: &Context, repo_root: &Path) -> Option<usize> {
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")

View File

@ -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(

View File

@ -85,10 +85,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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)

View File

@ -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`

View File

@ -133,13 +133,13 @@ impl<'a> ModuleRenderer<'a> {
}
pub enum FixtureProvider {
GIT,
HG,
Git,
Hg,
}
pub fn fixture_repo(provider: FixtureProvider) -> io::Result<TempDir> {
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<TempDir> {
Ok(path)
}
FixtureProvider::HG => {
FixtureProvider::Hg => {
let path = tempfile::tempdir()?;
Command::new("hg")