Skip to content

Commit 0ae61c7

Browse files
authored
chore(clippy): fix new lints (starship#4002)
1 parent a0a6c94 commit 0ae61c7

32 files changed

+114
-124
lines changed

.github/config-schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@
14761476
"definitions": {
14771477
"AwsConfig": {
14781478
"title": "AWS",
1479-
"description": "The `aws` module shows the current AWS region and profile when credentials or a `credential_process` have been setup. This is based on `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env var with `~/.aws/config` file. This module also shows an expiration timer when using temporary credentials.\n\nThe module will display a profile only if its credentials are present in `~/.aws/credentials` or a `credential_process` is defined in `~/.aws/config`. Alternatively, having any of the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, or `AWS_SESSION_TOKEN` env vars defined will also suffice.\n\nWhen using [aws-vault](https://github.com/99designs/aws-vault) the profile is read from the `AWS_VAULT` env var and the credentials expiration date is read from the `AWS_SESSION_EXPIRATION` env var.\n\nWhen using [awsu](https://github.com/kreuzwerker/awsu) the profile is read from the `AWSU_PROFILE` env var.\n\nWhen using [AWSume](https://awsu.me) the profile is read from the `AWSUME_PROFILE` env var and the credentials expiration date is read from the `AWSUME_EXPIRATION` env var.",
1479+
"description": "The `aws` module shows the current AWS region and profile when credentials or a `credential_process` have been setup. This is based on `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env var with `~/.aws/config` file. This module also shows an expiration timer when using temporary credentials.\n\nThe module will display a profile only if its credentials are present in `~/.aws/credentials` or a `credential_process` is defined in `~/.aws/config`. Alternatively, having any of the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, or `AWS_SESSION_TOKEN` env vars defined will also suffice.\n\nWhen using [aws-vault](https://github.com/99designs/aws-vault) the profile is read from the `AWS_VAULT` env var and the credentials expiration date is read from the `AWS_SESSION_EXPIRATION` env var.\n\nWhen using [awsu](https://github.com/kreuzwerker/awsu) the profile is read from the `AWSU_PROFILE` env var.\n\nWhen using [`AWSume`](https://awsu.me) the profile is read from the `AWSUME_PROFILE` env var and the credentials expiration date is read from the `AWSUME_EXPIRATION` env var.",
14801480
"type": "object",
14811481
"properties": {
14821482
"format": {

src/config.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ where
3434
}
3535
}
3636

37-
/// Helper function that will call ModuleConfig::from_config(config) if config is Some,
38-
/// or ModuleConfig::default() if config is None.
37+
/// Helper function that will call `ModuleConfig::from_config(config) if config is Some,
38+
/// or `ModuleConfig::default()` if config is None.
3939
fn try_load(config: Option<&'a Value>) -> Self {
4040
config.map(Self::load).unwrap_or_default()
4141
}
4242
}
4343

4444
impl<'a, T: Deserialize<'a> + Default> ModuleConfig<'a, ValueError> for T {
45-
/// Create ValueDeserializer wrapper and use it to call Deserialize::deserialize on it.
45+
/// Create `ValueDeserializer` wrapper and use it to call `Deserialize::deserialize` on it.
4646
fn from_config(config: &'a Value) -> Result<Self, ValueError> {
4747
let deserializer = ValueDeserializer::new(config);
4848
T::deserialize(deserializer)
@@ -72,8 +72,8 @@ where
7272
{
7373
let either = Either::<Vec<T>, T>::deserialize(deserializer)?;
7474
match either {
75-
Either::First(v) => Ok(VecOr(v)),
76-
Either::Second(s) => Ok(VecOr(vec![s])),
75+
Either::First(v) => Ok(Self(v)),
76+
Either::Second(s) => Ok(Self(vec![s])),
7777
}
7878
}
7979
}
@@ -244,7 +244,7 @@ impl StarshipConfig {
244244
pub fn get_custom_modules(&self) -> Option<&toml::value::Table> {
245245
self.get_config(&["custom"])?.as_table()
246246
}
247-
/// Get the table of all the registered env_var modules, if any
247+
/// Get the table of all the registered `env_var` modules, if any
248248
pub fn get_env_var_modules(&self) -> Option<&toml::value::Table> {
249249
self.get_config(&["env_var"])?.as_table()
250250
}
@@ -268,7 +268,7 @@ where
268268
- 'bold'
269269
- 'italic'
270270
- 'inverted'
271-
- '<color>' (see the parse_color_string doc for valid color strings)
271+
- '<color>' (see the `parse_color_string` doc for valid color strings)
272272
*/
273273
pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> {
274274
style_string
@@ -506,8 +506,8 @@ mod tests {
506506
{
507507
let s = String::deserialize(deserializer)?;
508508
match s.to_ascii_lowercase().as_str() {
509-
"on" => Ok(Switch::On),
510-
_ => Ok(Switch::Off),
509+
"on" => Ok(Self::On),
510+
_ => Ok(Self::Off),
511511
}
512512
}
513513
}

src/configs/aws.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::collections::HashMap;
2525
/// When using [awsu](https://github.com/kreuzwerker/awsu) the profile
2626
/// is read from the `AWSU_PROFILE` env var.
2727
///
28-
/// When using [AWSume](https://awsu.me) the profile
28+
/// When using [`AWSume`](https://awsu.me) the profile
2929
/// is read from the `AWSUME_PROFILE` env var and the credentials expiration
3030
/// date is read from the `AWSUME_EXPIRATION` env var.
3131
pub struct AwsConfig<'a> {

src/configs/starship_root.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub const PROMPT_ORDER: &[&str] = &[
9999
// On changes please also update `Default` for the `FullConfig` struct in `mod.rs`
100100
impl<'a> Default for StarshipRootConfig {
101101
fn default() -> Self {
102-
StarshipRootConfig {
102+
Self {
103103
schema: "https://starship.rs/config-schema.json".to_string(),
104104
format: "$all".to_string(),
105105
right_format: "".to_string(),

src/configure.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ fn handle_update_configuration(doc: &mut Document, name: &str, value: &str) -> R
6161
}
6262

6363
let mut new_value = toml_edit::Value::from_str(value)
64-
.map(toml_edit::Item::Value)
65-
.unwrap_or_else(|_| toml_edit::value(value));
64+
.map_or_else(|_| toml_edit::value(value), toml_edit::Item::Value);
6665

6766
if let Some(value) = current_item.as_value() {
6867
*new_value.as_value_mut().unwrap().decor_mut() = value.decor().clone();
@@ -147,7 +146,7 @@ fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value
147146
for &segment in parents {
148147
source_cursor = if let Some(child) = source_cursor
149148
.get_mut(segment)
150-
.and_then(|value| value.as_table_mut())
149+
.and_then(toml::Value::as_table_mut)
151150
{
152151
child
153152
} else {

src/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'a> Context<'a> {
337337
)
338338
}
339339

340-
/// Attempt to execute several commands with exec_cmd, return the results of the first that works
340+
/// Attempt to execute several commands with `exec_cmd`, return the results of the first that works
341341
pub fn exec_cmds_return_first(&self, commands: Vec<Vec<&str>>) -> Option<CommandOutput> {
342342
commands
343343
.iter()
@@ -513,7 +513,7 @@ impl<'a> ScanDir<'a> {
513513
self
514514
}
515515

516-
/// based on the current PathBuf check to see
516+
/// based on the current `PathBuf` check to see
517517
/// if any of this criteria match or exist and returning a boolean
518518
pub fn is_match(&self) -> bool {
519519
self.dir_contents.has_any_extension(self.extensions)
@@ -628,7 +628,7 @@ pub struct Properties {
628628

629629
impl Default for Properties {
630630
fn default() -> Self {
631-
Properties {
631+
Self {
632632
status_code: None,
633633
pipestatus: None,
634634
terminal_width: default_width(),

src/formatter/string_formatter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub struct StringFormatter<'a> {
6262
}
6363

6464
impl<'a> StringFormatter<'a> {
65-
/// Creates an instance of StringFormatter from a format string
65+
/// Creates an instance of `StringFormatter` from a format string
6666
///
6767
/// This method will throw an Error when the given format string fails to parse.
6868
pub fn new(format: &'a str) -> Result<Self, StringFormatterError> {
@@ -88,7 +88,7 @@ impl<'a> StringFormatter<'a> {
8888
})
8989
}
9090

91-
/// A StringFormatter that does no formatting, parse just returns the raw text
91+
/// A `StringFormatter` that does no formatting, parse just returns the raw text
9292
pub fn raw(text: &'a str) -> Self {
9393
Self {
9494
format: vec![FormatElement::Text(text.into())],

src/formatter/version.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::string_formatter::StringFormatterError;
22
use super::StringFormatter;
3+
use crate::segment;
34
use once_cell::sync::Lazy;
45
use std::ops::Deref;
56
use versions::Versioning;
@@ -9,9 +10,9 @@ pub struct VersionFormatter<'a> {
910
}
1011

1112
impl<'a> VersionFormatter<'a> {
12-
/// Creates an instance of a VersionFormatter from a format string
13+
/// Creates an instance of a `VersionFormatter` from a format string
1314
///
14-
/// Like the StringFormatter, this will throw an error when the string isn't
15+
/// Like the `StringFormatter`, this will throw an error when the string isn't
1516
/// parseable.
1617
pub fn new(format: &'a str) -> Result<Self, StringFormatterError> {
1718
let formatter = StringFormatter::new(format)?;
@@ -56,7 +57,7 @@ impl<'a> VersionFormatter<'a> {
5657
formatted.map(|segments| {
5758
segments
5859
.iter()
59-
.map(|segment| segment.value())
60+
.map(segment::Segment::value)
6061
.collect::<String>()
6162
})
6263
}

src/init/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl StarshipPath {
4040
self.str_path().map(|p| shell_words::quote(p).into_owned())
4141
}
4242

43-
/// PowerShell specific path escaping
43+
/// `PowerShell` specific path escaping
4444
fn sprint_pwsh(&self) -> io::Result<String> {
4545
self.str_path()
4646
.map(|s| s.replace('\'', "''"))

src/module.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::context::Shell;
2+
use crate::segment;
23
use crate::segment::{FillSegment, Segment};
34
use crate::utils::wrap_colorseq_for_shell;
45
use ansi_term::{ANSIString, ANSIStrings};
@@ -139,13 +140,10 @@ impl<'a> Module<'a> {
139140

140141
/// Get values of the module's segments
141142
pub fn get_segments(&self) -> Vec<&str> {
142-
self.segments
143-
.iter()
144-
.map(|segment| segment.value())
145-
.collect()
143+
self.segments.iter().map(segment::Segment::value).collect()
146144
}
147145

148-
/// Returns a vector of colored ANSIString elements to be later used with
146+
/// Returns a vector of colored `ANSIString` elements to be later used with
149147
/// `ANSIStrings()` to optimize ANSI codes
150148
pub fn ansi_strings(&self) -> Vec<ANSIString> {
151149
self.ansi_strings_for_shell(Shell::Unknown, None)

src/modules/aws.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn get_aws_region_from_config(
8989
let config = get_config(context, aws_config)?;
9090
let section = get_profile_config(config, aws_profile)?;
9191

92-
section.get("region").map(|region| region.to_owned())
92+
section.get("region").map(std::borrow::ToOwned::to_owned)
9393
}
9494

9595
fn get_aws_profile_and_region(

src/modules/c.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
6565
// so again we always want the first semver-ish word.
6666
VersionFormatter::format_module_version(
6767
module.get_name(),
68-
c_compiler_info.split_whitespace().find_map(
69-
|word| match Version::parse(word) {
70-
Ok(_v) => Some(word),
71-
Err(_e) => None,
72-
},
73-
)?,
68+
c_compiler_info
69+
.split_whitespace()
70+
.find(|word| Version::parse(word).is_ok())?,
7471
config.version_format,
7572
)
7673
.map(Cow::Owned)

src/modules/cmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::formatter::VersionFormatter;
44
use crate::configs::cmake::CMakeConfig;
55
use crate::formatter::StringFormatter;
66

7-
/// Creates a module with the current CMake version
7+
/// Creates a module with the current `CMake` version
88
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
99
let mut module = context.new_module("cmake");
1010
let config = CMakeConfig::try_load(module.config);

src/modules/custom.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> {
9292
Some(module)
9393
}
9494

95-
/// Return the invoking shell, using `shell` and fallbacking in order to STARSHIP_SHELL and "sh"/"cmd"
95+
/// Return the invoking shell, using `shell` and fallbacking in order to `STARSHIP_SHELL` and "sh"/"cmd"
9696
fn get_shell<'a, 'b>(
9797
shell_args: &'b [&'a str],
9898
context: &Context,
@@ -235,7 +235,7 @@ fn exec_command(cmd: &str, context: &Context, config: &CustomConfig) -> Option<S
235235
}
236236
}
237237

238-
/// If the specified shell refers to PowerShell, adds the arguments "-Command -" to the
238+
/// If the specified shell refers to `PowerShell`, adds the arguments "-Command -" to the
239239
/// given command.
240240
/// Retruns `false` if the shell shell expects scripts as arguments, `true` if as `stdin`.
241241
fn handle_shell(command: &mut Command, shell: &str, shell_args: &[&str]) -> bool {
@@ -289,7 +289,10 @@ mod tests {
289289
fn render_cmd(cmd: &str) -> io::Result<Option<String>> {
290290
let dir = tempfile::tempdir()?;
291291
let cmd = cmd.to_owned();
292-
let shell = SHELL.iter().map(|s| s.to_owned()).collect::<Vec<_>>();
292+
let shell = SHELL
293+
.iter()
294+
.map(std::borrow::ToOwned::to_owned)
295+
.collect::<Vec<_>>();
293296
let out = ModuleRenderer::new("custom.test")
294297
.path(dir.path())
295298
.config(toml::toml! {
@@ -308,7 +311,10 @@ mod tests {
308311
fn render_when(cmd: &str) -> io::Result<bool> {
309312
let dir = tempfile::tempdir()?;
310313
let cmd = cmd.to_owned();
311-
let shell = SHELL.iter().map(|s| s.to_owned()).collect::<Vec<_>>();
314+
let shell = SHELL
315+
.iter()
316+
.map(std::borrow::ToOwned::to_owned)
317+
.collect::<Vec<_>>();
312318
let out = ModuleRenderer::new("custom.test")
313319
.path(dir.path())
314320
.config(toml::toml! {
@@ -593,7 +599,7 @@ mod tests {
593599
let actual = ModuleRenderer::new("custom.test")
594600
.path(dir.path())
595601
.config(toml::toml! {
596-
command_timeout = 100000
602+
command_timeout = 100_000
597603
[custom.test]
598604
format = "test"
599605
when = when

src/modules/directory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::formatter::StringFormatter;
2222
///
2323
/// **Contraction**
2424
/// - Paths beginning with the home directory or with a git repo right inside
25-
/// the home directory will be contracted to `~`, or the set HOME_SYMBOL
25+
/// the home directory will be contracted to `~`, or the set `HOME_SYMBOL`
2626
/// - Paths containing a git repo will contract to begin at the repo root
2727
///
2828
/// **Substitution**

src/modules/docker_context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ use crate::utils;
99
/// Creates a module with the currently active Docker context
1010
///
1111
/// Will display the Docker context if the following criteria are met:
12-
/// - There is a non-empty environment variable named DOCKER_HOST
13-
/// - Or there is a non-empty environment variable named DOCKER_CONTEXT
12+
/// - There is a non-empty environment variable named `DOCKER_HOST`
13+
/// - Or there is a non-empty environment variable named `DOCKER_CONTEXT`
1414
/// - Or there is a file named `$HOME/.docker/config.json`
1515
/// - Or a file named `$DOCKER_CONFIG/config.json`
1616
/// - The file is JSON and contains a field named `currentContext`
1717
/// - The value of `currentContext` is not `default`
1818
/// - If multiple criterias are met, we use the following order to define the docker context:
19-
/// - DOCKER_HOST, DOCKER_CONTEXT, $HOME/.docker/config.json, $DOCKER_CONFIG/config.json
20-
/// - (This is the same order docker follows, as DOCKER_HOST and DOCKER_CONTEXT override the
19+
/// - `DOCKER_HOST`, `DOCKER_CONTEXT`, $HOME/.docker/config.json, $`DOCKER_CONFIG/config.json`
20+
/// - (This is the same order docker follows, as `DOCKER_HOST` and `DOCKER_CONTEXT` override the
2121
/// config)
2222
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
2323
let mut module = context.new_module("docker_context");

src/modules/dotnet.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ fn get_local_dotnet_files(context: &Context) -> Result<Vec<DotNetFile>, std::io:
264264
fn get_dotnet_file_type(path: &Path) -> Option<FileType> {
265265
let file_name_lower = map_str_to_lower(path.file_name());
266266

267-
match file_name_lower.as_ref().map(|f| f.as_ref()) {
267+
match file_name_lower.as_ref().map(std::convert::AsRef::as_ref) {
268268
Some(GLOBAL_JSON_FILE) => return Some(FileType::GlobalJson),
269269
Some(PROJECT_JSON_FILE) => return Some(FileType::ProjectJson),
270270
_ => (),
271271
};
272272

273273
let extension_lower = map_str_to_lower(path.extension());
274274

275-
match extension_lower.as_ref().map(|f| f.as_ref()) {
275+
match extension_lower.as_ref().map(std::convert::AsRef::as_ref) {
276276
Some("sln") => return Some(FileType::SolutionFile),
277277
Some("csproj" | "fsproj" | "xproj") => return Some(FileType::ProjectFile),
278278
Some("props" | "targets") => return Some(FileType::MsBuildFile),

src/modules/env_var.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::configs::env_var::EnvVarConfig;
55
use crate::formatter::StringFormatter;
66
use crate::segment::Segment;
77

8-
/// Creates env_var_module displayer which displays all configured environmental variables
8+
/// Creates `env_var_module` displayer which displays all configured environmental variables
99
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
1010
let config_table = context.config.get_env_var_modules()?;
1111
let mut env_modules = config_table
@@ -22,7 +22,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
2222
Some(env_var_displayer(env_modules, context))
2323
}
2424

25-
/// A utility module to display multiple env_variable modules
25+
/// A utility module to display multiple `env_variable` modules
2626
fn env_var_displayer<'a>(modules: Vec<Module>, context: &'a Context) -> Module<'a> {
2727
let mut module = context.new_module("env_var_displayer");
2828

@@ -37,9 +37,9 @@ fn env_var_displayer<'a>(modules: Vec<Module>, context: &'a Context) -> Module<'
3737
/// Creates a module with the value of the chosen environment variable
3838
///
3939
/// Will display the environment variable's value if all of the following criteria are met:
40-
/// - env_var.disabled is absent or false
41-
/// - env_var.variable is defined
42-
/// - a variable named as the value of env_var.variable is defined
40+
/// - `env_var.disabled` is absent or false
41+
/// - `env_var.variable` is defined
42+
/// - a variable named as the value of `env_var.variable` is defined
4343
fn env_var_module<'a>(module_config_path: Vec<&str>, context: &'a Context) -> Option<Module<'a>> {
4444
let mut module = context.new_module(&module_config_path.join("."));
4545
let config_value = context.config.get_config(&module_config_path);

src/modules/gcloud.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
121121
.project_aliases
122122
.get(project.as_ref())
123123
.copied()
124-
.map(Cow::Borrowed)
125-
.unwrap_or(project)
124+
.map_or(project, Cow::Borrowed)
126125
})
127126
.map(Ok),
128127
"active" => Some(Ok(Cow::Borrowed(&gcloud_context.config_name))),

src/modules/git_commit.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ fn id_to_hex_abbrev(bytes: &[u8], len: usize) -> String {
9393
bytes
9494
.iter()
9595
.map(|b| format!("{:02x}", b))
96-
.collect::<Vec<String>>()
97-
.join("")
96+
.collect::<String>()
9897
.chars()
9998
.take(len)
10099
.collect()

0 commit comments

Comments
 (0)