1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

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)] #[derive(Debug, PartialEq, Clone)]
enum Switch { enum Switch {
ON, On,
OFF, Off,
} }
impl<'a> ModuleConfig<'a> for Switch { impl<'a> ModuleConfig<'a> for Switch {
fn from_config(config: &'a Value) -> Option<Self> { fn from_config(config: &'a Value) -> Option<Self> {
match config.as_str()? { match config.as_str()? {
"on" => Some(Self::ON), "on" => Some(Self::On),
"off" => Some(Self::OFF), "off" => Some(Self::Off),
_ => None, _ => None,
} }
} }
@ -601,15 +601,15 @@ mod tests {
switch_b = "any" switch_b = "any"
}; };
let default_config = TestConfig { let default_config = TestConfig {
switch_a: Switch::OFF, switch_a: Switch::Off,
switch_b: Switch::OFF, switch_b: Switch::Off,
switch_c: Switch::OFF, switch_c: Switch::Off,
}; };
let rust_config = default_config.load_config(&config); let rust_config = default_config.load_config(&config);
assert_eq!(rust_config.switch_a, Switch::ON); assert_eq!(rust_config.switch_a, Switch::On);
assert_eq!(rust_config.switch_b, Switch::OFF); assert_eq!(rust_config.switch_b, Switch::Off);
assert_eq!(rust_config.switch_c, Switch::OFF); assert_eq!(rust_config.switch_c, Switch::Off);
} }
#[test] #[test]

View File

@ -332,9 +332,9 @@ impl DirContents {
); );
Ok(DirContents { Ok(DirContents {
folders,
files, files,
file_names, file_names,
folders,
extensions, 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::{error::Error, iterators::Pair, Parser};
use pest_derive::*; use pest_derive::*;

View File

@ -294,7 +294,7 @@ mod tests {
#[test] #[test]
fn test_render_branch_only_attached_on_branch() -> io::Result<()> { 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") Command::new("git")
.args(&["checkout", "-b", "test_branch"]) .args(&["checkout", "-b", "test_branch"])
@ -322,7 +322,7 @@ mod tests {
#[test] #[test]
fn test_render_branch_only_attached_on_detached() -> io::Result<()> { 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") Command::new("git")
.args(&["checkout", "@~1"]) .args(&["checkout", "@~1"])
@ -394,7 +394,7 @@ mod tests {
truncation_symbol: &str, truncation_symbol: &str,
config_options: &str, config_options: &str,
) -> io::Result<()> { ) -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
Command::new("git") Command::new("git")
.args(&["checkout", "-b", branch_name]) .args(&["checkout", "-b", branch_name])
@ -433,7 +433,7 @@ mod tests {
config_options: &str, config_options: &str,
expected: T, expected: T,
) -> io::Result<()> { ) -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
Command::new("git") Command::new("git")
.args(&["checkout", "-b", branch_name]) .args(&["checkout", "-b", branch_name])

View File

@ -135,7 +135,7 @@ mod tests {
#[test] #[test]
fn test_render_commit_hash() -> io::Result<()> { 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") let mut git_output = Command::new("git")
.args(&["rev-parse", "HEAD"]) .args(&["rev-parse", "HEAD"])
@ -167,7 +167,7 @@ mod tests {
#[test] #[test]
fn test_render_commit_hash_len_override() -> io::Result<()> { 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") let mut git_output = Command::new("git")
.args(&["rev-parse", "HEAD"]) .args(&["rev-parse", "HEAD"])
@ -200,7 +200,7 @@ mod tests {
#[test] #[test]
fn test_render_commit_hash_only_detached_on_branch() -> io::Result<()> { 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") let actual = ModuleRenderer::new("git_commit")
.path(&repo_dir.path()) .path(&repo_dir.path())
@ -214,7 +214,7 @@ mod tests {
#[test] #[test]
fn test_render_commit_hash_only_detached_on_detached() -> io::Result<()> { 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") Command::new("git")
.args(&["checkout", "@~1"]) .args(&["checkout", "@~1"])
@ -247,7 +247,7 @@ mod tests {
#[test] #[test]
fn test_render_commit_hash_with_tag_enabled() -> io::Result<()> { 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") let mut git_commit = Command::new("git")
.args(&["rev-parse", "HEAD"]) .args(&["rev-parse", "HEAD"])
@ -290,7 +290,7 @@ mod tests {
#[test] #[test]
fn test_render_commit_hash_only_detached_on_detached_with_tag_enabled() -> io::Result<()> { 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") Command::new("git")
.args(&["checkout", "@~1"]) .args(&["checkout", "@~1"])
@ -344,7 +344,7 @@ mod tests {
fn test_latest_tag_shown_with_tag_enabled() -> io::Result<()> { fn test_latest_tag_shown_with_tag_enabled() -> io::Result<()> {
use std::{thread, time}; 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") let mut git_commit = Command::new("git")
.args(&["rev-parse", "HEAD"]) .args(&["rev-parse", "HEAD"])

View File

@ -7,7 +7,7 @@ use crate::configs::git_status::GitStatusConfig;
use crate::context::Repo; use crate::context::Repo;
use crate::formatter::StringFormatter; use crate::formatter::StringFormatter;
use crate::segment::Segment; use crate::segment::Segment;
use std::path::PathBuf; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
const ALL_STATUS_FORMAT: &str = "$conflicted$stashed$deleted$renamed$modified$staged$untracked"; 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...) /// 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"); log::debug!("New repo status created");
let mut repo_status = RepoStatus::default(); let mut repo_status = RepoStatus::default();
@ -211,7 +211,7 @@ fn get_repo_status(context: &Context, repo_root: &PathBuf) -> Option<RepoStatus>
Some(repo_status) 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( let stash_output = context.exec_cmd(
"git", "git",
&[ &[
@ -359,7 +359,7 @@ mod tests {
#[test] #[test]
fn shows_behind() -> io::Result<()> { fn shows_behind() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
behind(&repo_dir.path())?; behind(&repo_dir.path())?;
@ -374,7 +374,7 @@ mod tests {
#[test] #[test]
fn shows_behind_with_count() -> io::Result<()> { 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())?; behind(&repo_dir.path())?;
@ -393,7 +393,7 @@ mod tests {
#[test] #[test]
fn shows_ahead() -> io::Result<()> { 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()?; File::create(repo_dir.path().join("readme.md"))?.sync_all()?;
ahead(&repo_dir.path())?; ahead(&repo_dir.path())?;
@ -409,7 +409,7 @@ mod tests {
#[test] #[test]
fn shows_ahead_with_count() -> io::Result<()> { 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()?; File::create(repo_dir.path().join("readme.md"))?.sync_all()?;
ahead(&repo_dir.path())?; ahead(&repo_dir.path())?;
@ -429,7 +429,7 @@ mod tests {
#[test] #[test]
fn shows_diverged() -> io::Result<()> { fn shows_diverged() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
diverge(&repo_dir.path())?; diverge(&repo_dir.path())?;
@ -444,7 +444,7 @@ mod tests {
#[test] #[test]
fn shows_diverged_with_count() -> io::Result<()> { 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())?; diverge(&repo_dir.path())?;
@ -463,7 +463,7 @@ mod tests {
#[test] #[test]
fn shows_conflicted() -> io::Result<()> { fn shows_conflicted() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
create_conflict(&repo_dir.path())?; create_conflict(&repo_dir.path())?;
@ -478,7 +478,7 @@ mod tests {
#[test] #[test]
fn shows_conflicted_with_count() -> io::Result<()> { 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())?; create_conflict(&repo_dir.path())?;
@ -497,7 +497,7 @@ mod tests {
#[test] #[test]
fn shows_untracked_file() -> io::Result<()> { 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())?; create_untracked(&repo_dir.path())?;
@ -512,7 +512,7 @@ mod tests {
#[test] #[test]
fn shows_untracked_file_with_count() -> io::Result<()> { 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())?; create_untracked(&repo_dir.path())?;
@ -531,7 +531,7 @@ mod tests {
#[test] #[test]
fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> { 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())?; create_untracked(&repo_dir.path())?;
@ -552,7 +552,7 @@ mod tests {
#[test] #[test]
fn shows_stashed() -> io::Result<()> { fn shows_stashed() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
barrier(); barrier();
create_stash(&repo_dir.path())?; create_stash(&repo_dir.path())?;
@ -574,7 +574,7 @@ mod tests {
#[test] #[test]
fn shows_stashed_with_count() -> io::Result<()> { fn shows_stashed_with_count() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
barrier(); barrier();
create_stash(&repo_dir.path())?; create_stash(&repo_dir.path())?;
@ -601,7 +601,7 @@ mod tests {
#[test] #[test]
fn shows_modified() -> io::Result<()> { fn shows_modified() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GIT)?; let repo_dir = fixture_repo(FixtureProvider::Git)?;
create_modified(&repo_dir.path())?; create_modified(&repo_dir.path())?;
@ -616,7 +616,7 @@ mod tests {
#[test] #[test]
fn shows_modified_with_count() -> io::Result<()> { 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())?; create_modified(&repo_dir.path())?;
@ -635,7 +635,7 @@ mod tests {
#[test] #[test]
fn shows_staged_file() -> io::Result<()> { 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())?; create_staged(&repo_dir.path())?;
@ -650,7 +650,7 @@ mod tests {
#[test] #[test]
fn shows_staged_file_with_count() -> io::Result<()> { 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())?; create_staged(&repo_dir.path())?;
@ -676,7 +676,7 @@ mod tests {
#[test] #[test]
fn shows_renamed_file() -> io::Result<()> { 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())?; create_renamed(&repo_dir.path())?;
@ -691,7 +691,7 @@ mod tests {
#[test] #[test]
fn shows_renamed_file_with_count() -> io::Result<()> { 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())?; create_renamed(&repo_dir.path())?;
@ -710,7 +710,7 @@ mod tests {
#[test] #[test]
fn shows_deleted_file() -> io::Result<()> { 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())?; create_deleted(&repo_dir.path())?;
@ -725,7 +725,7 @@ mod tests {
#[test] #[test]
fn shows_deleted_file_with_count() -> io::Result<()> { 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())?; create_deleted(&repo_dir.path())?;
@ -748,7 +748,7 @@ mod tests {
#[test] #[test]
#[ignore] #[ignore]
fn ignore_manually_renamed() -> io::Result<()> { 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("a"))?.sync_all()?;
File::create(repo_dir.path().join("b"))?.sync_all()?; File::create(repo_dir.path().join("b"))?.sync_all()?;
Command::new("git") Command::new("git")

View File

@ -94,7 +94,7 @@ fn get_graphemes(text: &str, length: usize) -> String {
} }
fn graphemes_len(text: &str) -> usize { fn graphemes_len(text: &str) -> usize {
UnicodeSegmentation::graphemes(&text[..], true).count() UnicodeSegmentation::graphemes(text, true).count()
} }
#[cfg(test)] #[cfg(test)]
@ -132,7 +132,7 @@ mod tests {
#[test] #[test]
#[ignore] #[ignore]
fn test_hg_disabled_per_default() -> io::Result<()> { 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(); let repo_dir = tempdir.path();
run_hg(&["whatever", "blubber"], &repo_dir)?; run_hg(&["whatever", "blubber"], &repo_dir)?;
expect_hg_branch_with_config( expect_hg_branch_with_config(
@ -176,7 +176,7 @@ mod tests {
#[test] #[test]
#[ignore] #[ignore]
fn test_hg_bookmark() -> io::Result<()> { fn test_hg_bookmark() -> io::Result<()> {
let tempdir = fixture_repo(FixtureProvider::HG)?; let tempdir = fixture_repo(FixtureProvider::Hg)?;
let repo_dir = tempdir.path(); let repo_dir = tempdir.path();
run_hg(&["bookmark", "bookmark-101"], &repo_dir)?; run_hg(&["bookmark", "bookmark-101"], &repo_dir)?;
expect_hg_branch_with_config( expect_hg_branch_with_config(
@ -190,7 +190,7 @@ mod tests {
#[test] #[test]
#[ignore] #[ignore]
fn test_default_truncation_symbol() -> io::Result<()> { fn test_default_truncation_symbol() -> io::Result<()> {
let tempdir = fixture_repo(FixtureProvider::HG)?; let tempdir = fixture_repo(FixtureProvider::Hg)?;
let repo_dir = tempdir.path(); let repo_dir = tempdir.path();
run_hg(&["branch", "-f", "branch-name-101"], &repo_dir)?; run_hg(&["branch", "-f", "branch-name-101"], &repo_dir)?;
run_hg( run_hg(
@ -218,7 +218,7 @@ mod tests {
#[test] #[test]
#[ignore] #[ignore]
fn test_configured_symbols() -> io::Result<()> { fn test_configured_symbols() -> io::Result<()> {
let tempdir = fixture_repo(FixtureProvider::HG)?; let tempdir = fixture_repo(FixtureProvider::Hg)?;
let repo_dir = tempdir.path(); let repo_dir = tempdir.path();
run_hg(&["branch", "-f", "branch-name-121"], &repo_dir)?; run_hg(&["branch", "-f", "branch-name-121"], &repo_dir)?;
run_hg( run_hg(
@ -252,7 +252,7 @@ mod tests {
#[test] #[test]
#[ignore] #[ignore]
fn test_configured_style() -> io::Result<()> { fn test_configured_style() -> io::Result<()> {
let tempdir = fixture_repo(FixtureProvider::HG)?; let tempdir = fixture_repo(FixtureProvider::Hg)?;
let repo_dir = tempdir.path(); let repo_dir = tempdir.path();
run_hg(&["branch", "-f", "branch-name-131"], &repo_dir)?; run_hg(&["branch", "-f", "branch-name-131"], &repo_dir)?;
run_hg( 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())), None => Some(Ok(kube_ctx.as_str())),
Some(&alias) => Some(Ok(alias)), Some(&alias) => Some(Ok(alias)),
}, },
"namespace" => match &kube_ns { "namespace" => kube_ns.as_ref().map(|s| Ok(s.as_str())),
Some(kube_ns) => Some(Ok(kube_ns)),
None => None,
},
_ => None, _ => None,
}) })
.parse(None) .parse(None)

View File

@ -20,6 +20,8 @@ mod normalize {
use std::ffi::OsStr; use std::ffi::OsStr;
use std::path::{Component, Path, Prefix}; use std::path::{Component, Path, Prefix};
// allow because this mirrors std
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub enum NormalizedPrefix<'a> { pub enum NormalizedPrefix<'a> {
// No prefix, e.g. `\cat_pics` or `/cat_pics` // No prefix, e.g. `\cat_pics` or `/cat_pics`

View File

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