1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-01 01:04:00 +00:00

refactor: fix new clippy/compiler warnings (#3656)

This commit is contained in:
David Knaack 2022-02-25 05:31:01 +01:00 committed by GitHub
parent 1a8aa96b7f
commit 1745392909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 22 additions and 21 deletions

View File

@ -475,16 +475,19 @@ pub struct ScanDir<'a> {
}
impl<'a> ScanDir<'a> {
#[must_use]
pub const fn set_files(mut self, files: &'a [&'a str]) -> Self {
self.files = files;
self
}
#[must_use]
pub const fn set_extensions(mut self, extensions: &'a [&'a str]) -> Self {
self.extensions = extensions;
self
}
#[must_use]
pub const fn set_folders(mut self, folders: &'a [&'a str]) -> Self {
self.folders = folders;
self

View File

@ -111,6 +111,7 @@ impl<'a> StringFormatter<'a> {
///
/// - `Some(Ok(_))`: The value of this variable will be displayed in the format string.
///
#[must_use]
pub fn map<T, M>(mut self, mapper: M) -> Self
where
T: Into<Cow<'a, str>>,
@ -131,6 +132,7 @@ impl<'a> StringFormatter<'a> {
///
/// See `StringFormatter::map` for description on the parameters.
///
#[must_use]
pub fn map_no_escaping<T, M>(mut self, mapper: M) -> Self
where
T: Into<Cow<'a, str>>,
@ -152,6 +154,7 @@ impl<'a> StringFormatter<'a> {
/// the format strings of meta-variables can be cached properly.
///
/// See `StringFormatter::map` for description on the parameters.
#[must_use]
pub fn map_meta<M>(mut self, mapper: M) -> Self
where
M: Fn(&str, &BTreeSet<String>) -> Option<&'a str> + Sync,
@ -193,6 +196,7 @@ impl<'a> StringFormatter<'a> {
/// Maps variable name to an array of segments
///
/// See `StringFormatter::map` for description on the parameters.
#[must_use]
pub fn map_variables_to_segments<M>(mut self, mapper: M) -> Self
where
M: Fn(&str) -> Option<Result<Vec<Segment>, StringFormatterError>> + Sync,
@ -209,6 +213,7 @@ impl<'a> StringFormatter<'a> {
/// Maps variable name in a style string to its value
///
/// See `StringFormatter::map` for description on the parameters.
#[must_use]
pub fn map_style<T, M>(mut self, mapper: M) -> Self
where
T: Into<Cow<'a, str>>,

View File

@ -43,7 +43,7 @@ impl StarshipPath {
/// PowerShell specific path escaping
fn sprint_pwsh(&self) -> io::Result<String> {
self.str_path()
.map(|s| s.replace("'", "''"))
.map(|s| s.replace('\'', "''"))
.map(|s| format!("'{}'", s))
}
/// Command Shell specific path escaping

View File

@ -1,4 +1,4 @@
#![warn(clippy::disallowed_method)]
#![warn(clippy::disallowed_methods)]
#[macro_use]
extern crate shadow_rs;

View File

@ -1,4 +1,4 @@
#![warn(clippy::disallowed_method)]
#![warn(clippy::disallowed_methods)]
use clap::crate_authors;
use std::io;

View File

@ -209,8 +209,7 @@ where
current
} else {
let fill_size = term_width
.map(|tw| if tw > used { Some(tw - used) } else { None })
.flatten()
.and_then(|tw| if tw > used { Some(tw - used) } else { None })
.map(|remaining| remaining / chunks.len());
chunks
.into_iter()
@ -229,7 +228,7 @@ mod tests {
#[test]
fn test_all_modules_is_in_alphabetical_order() {
let mut sorted_modules: Vec<&str> = ALL_MODULES.iter().copied().collect();
let mut sorted_modules: Vec<&str> = ALL_MODULES.to_vec();
sorted_modules.sort_unstable();
assert_eq!(sorted_modules.as_slice(), ALL_MODULES);
}

View File

@ -123,7 +123,7 @@ fn shell_command(cmd: &str, shell_args: &[&str]) -> Option<Output> {
"Could not launch command with given shell or STARSHIP_SHELL env variable, retrying with /usr/bin/env sh"
);
#[allow(clippy::disallowed_method)]
#[allow(clippy::disallowed_methods)]
Command::new("/usr/bin/env")
.arg("sh")
.stdin(Stdio::piped())

View File

@ -41,9 +41,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
)
.join("config.json");
let docker_context_env =
std::array::IntoIter::new(["DOCKER_MACHINE_NAME", "DOCKER_HOST", "DOCKER_CONTEXT"])
.find_map(|env| context.get_env(env));
let docker_context_env = ["DOCKER_MACHINE_NAME", "DOCKER_HOST", "DOCKER_CONTEXT"]
.into_iter()
.find_map(|env| context.get_env(env));
let ctx = match docker_context_env {
Some(data) => data,

View File

@ -158,7 +158,7 @@ fn get_pulumi_workspace(context: &Context, name: &str, project_file: &Path) -> O
} else {
let mut hasher = Sha1::new();
hasher.update(project_file.to_str()?.as_bytes());
crate::utils::encode_to_hex(&hasher.finalize().to_vec())
crate::utils::encode_to_hex(&hasher.finalize())
};
let unique_file_name = format!("{}-{}-workspace.json", name, project_file);
let mut path = pulumi_home_dir(context)?;

View File

@ -76,13 +76,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
PipeStatusStatus::Pipe(_) => config.pipestatus_format,
_ => config.format,
};
let parsed = format_exit_code(
&exit_code.to_string(),
main_format,
Some(&pipestatus),
&config,
context,
);
let parsed = format_exit_code(exit_code, main_format, Some(&pipestatus), &config, context);
module.set_segments(match parsed {
Ok(segments) => segments,
@ -119,8 +113,8 @@ fn format_exit_code<'a>(
false => None,
};
let signal_number = raw_signal_number.map(|sn| sn.to_string());
let signal_name = raw_signal_number
.and_then(|sn| status_signal_name(sn).or_else(|| signal_number.as_deref()));
let signal_name =
raw_signal_number.and_then(|sn| status_signal_name(sn).or(signal_number.as_deref()));
// If not a signal and not a common meaning, it should at least print the raw exit code number
let maybe_exit_code_number = match common_meaning.is_none() && signal_name.is_none() {

View File

@ -75,7 +75,7 @@ pub fn create_command<T: AsRef<OsStr>>(binary_name: T) -> Result<Command> {
}
};
#[allow(clippy::disallowed_method)]
#[allow(clippy::disallowed_methods)]
let mut cmd = Command::new(full_path);
cmd.stderr(Stdio::piped())
.stdout(Stdio::piped())