mirror of
https://github.com/starship/starship.git
synced 2024-11-22 16:23:17 +01:00
fix: Applied clippy warnings (#2153)
* Applied changes suggested by clippy In general: 1. Prefer std::path::Path over std::path::PathBuf 2. Simplified code with string formating... Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com> * Fixed test Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com> * Fixed formatting Signed-off-by: Hanif Ariffin <hanif.ariffin.4326@gmail.com>
This commit is contained in:
parent
fb0381f7e0
commit
5722b17f9e
@ -225,7 +225,7 @@ impl DirContents {
|
||||
Self::from_path_with_timeout(base, Duration::from_secs(30))
|
||||
}
|
||||
|
||||
fn from_path_with_timeout(base: &PathBuf, timeout: Duration) -> Result<Self, std::io::Error> {
|
||||
fn from_path_with_timeout(base: &Path, timeout: Duration) -> Result<Self, std::io::Error> {
|
||||
let start = Instant::now();
|
||||
|
||||
let mut folders: HashSet<PathBuf> = HashSet::new();
|
||||
|
@ -14,7 +14,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
enum ShellEditMode {
|
||||
Normal,
|
||||
Insert,
|
||||
};
|
||||
}
|
||||
const ASSUMED_MODE: ShellEditMode = ShellEditMode::Insert;
|
||||
// TODO: extend config to more modes
|
||||
|
||||
|
@ -299,7 +299,7 @@ fn get_latest_sdk_from_cli() -> Option<Version> {
|
||||
fn parse_failed<T>() -> Option<T> {
|
||||
log::warn!("Unable to parse the output from `dotnet --list-sdks`.");
|
||||
None
|
||||
};
|
||||
}
|
||||
let latest_sdk = sdks_output
|
||||
.stdout
|
||||
.lines()
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Error, ErrorKind};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::{collections::HashMap, path::Path};
|
||||
|
||||
use super::{Context, Module, RootModuleConfig};
|
||||
|
||||
@ -14,7 +14,7 @@ type Project = String;
|
||||
type Region = String;
|
||||
type Active = String;
|
||||
|
||||
fn get_gcloud_account_from_config(current_config: &PathBuf) -> Option<Account> {
|
||||
fn get_gcloud_account_from_config(current_config: &Path) -> Option<Account> {
|
||||
let file = File::open(¤t_config).ok()?;
|
||||
let reader = BufReader::new(file);
|
||||
let lines = reader.lines().filter_map(Result::ok);
|
||||
@ -27,7 +27,7 @@ fn get_gcloud_account_from_config(current_config: &PathBuf) -> Option<Account> {
|
||||
Some(account.to_string())
|
||||
}
|
||||
|
||||
fn get_gcloud_project_from_config(current_config: &PathBuf) -> Option<Project> {
|
||||
fn get_gcloud_project_from_config(current_config: &Path) -> Option<Project> {
|
||||
let file = File::open(¤t_config).ok()?;
|
||||
let reader = BufReader::new(file);
|
||||
let lines = reader.lines().filter_map(Result::ok);
|
||||
@ -40,7 +40,7 @@ fn get_gcloud_project_from_config(current_config: &PathBuf) -> Option<Project> {
|
||||
Some(project.to_string())
|
||||
}
|
||||
|
||||
fn get_gcloud_region_from_config(current_config: &PathBuf) -> Option<Region> {
|
||||
fn get_gcloud_region_from_config(current_config: &Path) -> Option<Region> {
|
||||
let file = File::open(¤t_config).ok()?;
|
||||
let reader = BufReader::new(file);
|
||||
let lines = reader.lines().filter_map(Result::ok);
|
||||
@ -53,7 +53,7 @@ fn get_gcloud_region_from_config(current_config: &PathBuf) -> Option<Region> {
|
||||
Some(region.to_string())
|
||||
}
|
||||
|
||||
fn get_active_config(context: &Context, config_root: &PathBuf) -> Option<String> {
|
||||
fn get_active_config(context: &Context, config_root: &Path) -> Option<String> {
|
||||
let config_name = context.get_env("CLOUDSDK_ACTIVE_CONFIG_NAME").or_else(|| {
|
||||
let path = config_root.join("active_config");
|
||||
let file = File::open(&path).ok()?;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use git2::RepositoryState;
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use super::{Context, Module, RootModuleConfig};
|
||||
use crate::configs::git_state::GitStateConfig;
|
||||
@ -53,7 +53,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
/// During a git operation it will show: REBASING, BISECTING, MERGING, etc.
|
||||
fn get_state_description<'a>(
|
||||
state: RepositoryState,
|
||||
root: &'a std::path::PathBuf,
|
||||
root: &'a Path,
|
||||
config: &GitStateConfig<'a>,
|
||||
) -> Option<StateDescription<'a>> {
|
||||
match state {
|
||||
@ -104,7 +104,7 @@ fn get_state_description<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
fn describe_rebase<'a>(root: &'a PathBuf, rebase_config: &'a str) -> StateDescription<'a> {
|
||||
fn describe_rebase<'a>(root: &'a Path, rebase_config: &'a str) -> StateDescription<'a> {
|
||||
/*
|
||||
* Sadly, libgit2 seems to have some issues with reading the state of
|
||||
* interactive rebases. So, instead, we'll poke a few of the .git files
|
||||
|
@ -8,7 +8,7 @@ use regex::Regex;
|
||||
use semver::Version;
|
||||
use semver::VersionReq;
|
||||
use serde_json as json;
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
|
||||
/// Creates a module with the current Node.js version
|
||||
///
|
||||
@ -73,7 +73,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
Some(module)
|
||||
}
|
||||
|
||||
fn get_engines_version(base_dir: &PathBuf) -> Option<String> {
|
||||
fn get_engines_version(base_dir: &Path) -> Option<String> {
|
||||
let json_str = utils::read_file(base_dir.join("package.json")).ok()?;
|
||||
let package_json: json::Value = json::from_str(&json_str).ok()?;
|
||||
let raw_version = package_json.get("engines")?.get("node")?.as_str()?;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
|
||||
use super::{Context, Module, RootModuleConfig};
|
||||
use crate::configs::package::PackageConfig;
|
||||
@ -172,7 +172,7 @@ fn extract_meson_version(file_contents: &str) -> Option<String> {
|
||||
Some(formatted_version)
|
||||
}
|
||||
|
||||
fn get_package_version(base_dir: &PathBuf, config: &PackageConfig) -> Option<String> {
|
||||
fn get_package_version(base_dir: &Path, config: &PackageConfig) -> Option<String> {
|
||||
if let Ok(cargo_toml) = utils::read_file(base_dir.join("Cargo.toml")) {
|
||||
extract_cargo_version(&cargo_toml)
|
||||
} else if let Ok(package_json) = utils::read_file(base_dir.join("package.json")) {
|
||||
|
@ -42,7 +42,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
_ => None,
|
||||
})
|
||||
.map(|variable| match variable {
|
||||
"version" => format_php_version(&php_cmd_output.stdout).map(Ok),
|
||||
"version" => Some(Ok(format_php_version(&php_cmd_output.stdout))),
|
||||
_ => None,
|
||||
})
|
||||
.parse(None)
|
||||
@ -62,11 +62,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
}
|
||||
}
|
||||
|
||||
fn format_php_version(php_version: &str) -> Option<String> {
|
||||
let mut formatted_version = String::with_capacity(php_version.len() + 1);
|
||||
formatted_version.push('v');
|
||||
formatted_version.push_str(php_version);
|
||||
Some(formatted_version)
|
||||
fn format_php_version(php_version: &str) -> String {
|
||||
format!("v{}", php_version)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -80,7 +77,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_format_php_version() {
|
||||
let input = "7.3.8";
|
||||
assert_eq!(format_php_version(input), Some("v7.3.8".to_string()));
|
||||
assert_eq!(format_php_version(input), "v7.3.8".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user