Skip to content

Commit 6e38683

Browse files
authored
chore: fix new clippy lints (starship#4557)
1 parent 9b64f51 commit 6e38683

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+324
-324
lines changed

.github/config-schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@
16131613
"definitions": {
16141614
"AwsConfig": {
16151615
"title": "AWS",
1616-
"description": "The `aws` module shows the current AWS region and profile and an expiration timer when using temporary credentials. The output of the module uses the `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env vars and the `~/.aws/config` and `~/.aws/credentials` files as required.\n\nThe module will display a profile only if its credentials are present in `~/.aws/credentials` or if a `credential_process` or `sso_start_url` are 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. If the option `force_display` is set to `true`, all available information will be displayed even if no credentials per the conditions above are detected.\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.",
1616+
"description": "The `aws` module shows the current AWS region and profile and an expiration timer when using temporary credentials. The output of the module uses the `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env vars and the `~/.aws/config` and `~/.aws/credentials` files as required.\n\nThe module will display a profile only if its credentials are present in `~/.aws/credentials` or if a `credential_process` or `sso_start_url` are 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. If the option `force_display` is set to `true`, all available information will be displayed even if no credentials per the conditions above are detected.\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.",
16171617
"type": "object",
16181618
"properties": {
16191619
"format": {

build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn gen_presets_hook(mut file: &File) -> SdResult<()> {
3333
.to_str()
3434
.and_then(|v| v.strip_suffix(".toml"))
3535
.expect("Failed to process filename");
36-
presets.push_str(format!("print::Preset(\"{}\"),\n", name).as_str());
36+
presets.push_str(format!("print::Preset(\"{name}\"),\n").as_str());
3737
match_arms.push_str(
3838
format!(
3939
r#"

src/bug_report.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn create() {
2626
println!("Click this link to create a GitHub issue populated with your configuration:\n");
2727
}
2828

29-
println!("{}", link);
29+
println!("{link}");
3030
}
3131

3232
const UNKNOWN_SHELL: &str = "<unknown shell>";
@@ -225,11 +225,11 @@ fn get_shell_version(shell: &str) -> String {
225225
let time_limit = Duration::from_millis(500);
226226
match shell {
227227
"powershell" => exec_cmd(
228-
&shell,
228+
shell,
229229
&["(Get-Host | Select Version | Format-Table -HideTableHeaders | Out-String).trim()"],
230230
time_limit,
231231
),
232-
_ => exec_cmd(&shell, &["--version"], time_limit),
232+
_ => exec_cmd(shell, &["--version"], time_limit),
233233
}
234234
.map_or_else(
235235
|| UNKNOWN_VERSION.to_string(),

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl StarshipConfig {
141141
fn config_from_file() -> Option<Value> {
142142
let file_path = get_config_path()?;
143143

144-
let toml_content = match utils::read_file(&file_path) {
144+
let toml_content = match utils::read_file(file_path) {
145145
Ok(content) => {
146146
log::trace!("Config file content: \"\n{}\"", &content);
147147
Some(content)

src/configs/aws.rs

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

src/configs/starship_root.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Default for StarshipRootConfig {
118118
Self {
119119
schema: "https://starship.rs/config-schema.json".to_string(),
120120
format: "$all".to_string(),
121-
right_format: "".to_string(),
121+
right_format: String::new(),
122122
continuation_prompt: "[∙](bright-black) ".to_string(),
123123
scan_timeout: 30,
124124
command_timeout: 500,

src/configure.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn update_configuration(name: &str, value: &str) {
2424

2525
match handle_update_configuration(&mut doc, name, value) {
2626
Err(e) => {
27-
eprintln!("{}", e);
27+
eprintln!("{e}");
2828
process::exit(1);
2929
}
3030
_ => write_configuration(&doc),
@@ -99,7 +99,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) {
9999
"# $all is shorthand for {}",
100100
PROMPT_ORDER
101101
.iter()
102-
.map(|module_name| format!("${}", module_name))
102+
.map(|module_name| format!("${module_name}"))
103103
.collect::<String>()
104104
);
105105

@@ -110,7 +110,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) {
110110
"# $custom (excluding any modules already listed in `format`) is shorthand for {}",
111111
custom_modules
112112
.keys()
113-
.map(|module_name| format!("${{custom.{}}}", module_name))
113+
.map(|module_name| format!("${{custom.{module_name}}}"))
114114
.collect::<String>()
115115
);
116116
}
@@ -124,7 +124,7 @@ pub fn print_configuration(use_default: bool, paths: &[String]) {
124124

125125
let string_config = toml::to_string_pretty(&print_config).unwrap();
126126

127-
println!("{}", string_config);
127+
println!("{string_config}");
128128
}
129129

130130
fn extract_toml_paths(mut config: toml::Value, paths: &[String]) -> toml::Value {
@@ -186,7 +186,7 @@ pub fn toggle_configuration(name: &str, key: &str) {
186186

187187
match handle_toggle_configuration(&mut doc, name, key) {
188188
Err(e) => {
189-
eprintln!("{}", e);
189+
eprintln!("{e}");
190190
process::exit(1);
191191
}
192192
_ => write_configuration(&doc),
@@ -202,17 +202,17 @@ fn handle_toggle_configuration(doc: &mut Document, name: &str, key: &str) -> Res
202202

203203
let values = table
204204
.get_mut(name)
205-
.ok_or_else(|| format!("Given module '{}' not found in config file", name))?
205+
.ok_or_else(|| format!("Given module '{name}' not found in config file"))?
206206
.as_table_like_mut()
207-
.ok_or_else(|| format!("Given config entry '{}' is not a module", key))?;
207+
.ok_or_else(|| format!("Given config entry '{key}' is not a module"))?;
208208

209209
let old_value = values
210210
.get(key)
211-
.ok_or_else(|| format!("Given config key '{}' must exist in config file", key))?;
211+
.ok_or_else(|| format!("Given config key '{key}' must exist in config file"))?;
212212

213213
let old = old_value
214214
.as_bool()
215-
.ok_or_else(|| format!("Given config key '{}' must be in 'boolean' format", key))?;
215+
.ok_or_else(|| format!("Given config key '{key}' must be in 'boolean' format"))?;
216216

217217
let mut new_value = toml_edit::value(!old);
218218
// Above code already checks if it is a value (bool)
@@ -232,7 +232,7 @@ pub fn get_configuration() -> Value {
232232

233233
pub fn get_configuration_edit() -> Document {
234234
let file_path = get_config_path();
235-
let toml_content = match utils::read_file(&file_path) {
235+
let toml_content = match utils::read_file(file_path) {
236236
Ok(content) => {
237237
log::trace!("Config file content: \"\n{}\"", &content);
238238
Some(content)
@@ -260,7 +260,7 @@ pub fn write_configuration(doc: &Document) {
260260

261261
let config_str = doc.to_string();
262262

263-
File::create(&config_path)
263+
File::create(config_path)
264264
.and_then(|mut file| file.write_all(config_str.as_ref()))
265265
.expect("Error writing starship config");
266266
}
@@ -291,7 +291,7 @@ pub fn edit_configuration(editor_override: Option<&str>) -> Result<(), Box<dyn s
291291
.status();
292292

293293
if let Err(e) = res {
294-
eprintln!("Unable to launch editor {:?}", editor_cmd);
294+
eprintln!("Unable to launch editor {editor_cmd:?}");
295295
return Err(Box::new(e));
296296
}
297297

@@ -352,17 +352,17 @@ mod tests {
352352

353353
#[test]
354354
fn visual_empty_editor_set() {
355-
let actual = get_editor_internal(Some("".into()), Some("bar".into()));
355+
let actual = get_editor_internal(Some(String::new()), Some("bar".into()));
356356
assert_eq!("bar", actual);
357357
}
358358
#[test]
359359
fn visual_empty_editor_empty() {
360-
let actual = get_editor_internal(Some("".into()), Some("".into()));
360+
let actual = get_editor_internal(Some(String::new()), Some(String::new()));
361361
assert_eq!(STD_EDITOR, actual);
362362
}
363363
#[test]
364364
fn visual_empty_editor_not_set() {
365-
let actual = get_editor_internal(Some("".into()), None);
365+
let actual = get_editor_internal(Some(String::new()), None);
366366
assert_eq!(STD_EDITOR, actual);
367367
}
368368

@@ -373,7 +373,7 @@ mod tests {
373373
}
374374
#[test]
375375
fn visual_not_set_editor_empty() {
376-
let actual = get_editor_internal(None, Some("".into()));
376+
let actual = get_editor_internal(None, Some(String::new()));
377377
assert_eq!(STD_EDITOR, actual);
378378
}
379379
#[test]

src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn get_remote_repository_info(
631631
let branch_name = branch_name?;
632632
let branch = repository
633633
.branch_remote_ref(branch_name)
634-
.and_then(|r| r.ok())
634+
.and_then(std::result::Result::ok)
635635
.map(|r| r.shorten().to_string());
636636
let name = repository
637637
.branch_remote_name(branch_name)
@@ -849,7 +849,7 @@ mod tests {
849849

850850
let tmp_dir = tempfile::TempDir::new()?;
851851
let path = tmp_dir.path().join("a/xxx/yyy");
852-
fs::create_dir_all(&path)?;
852+
fs::create_dir_all(path)?;
853853

854854
// Set up a mock symlink
855855
let path_actual = tmp_dir.path().join("a/xxx");

src/formatter/parser.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ fn parse_style(style: Pair<Rule>) -> Vec<StyleElement> {
5858
.collect()
5959
}
6060

61-
pub fn parse(format: &str) -> Result<Vec<FormatElement>, Error<Rule>> {
62-
IdentParser::parse(Rule::expression, format).map(|pairs| {
63-
pairs
64-
.take_while(|pair| pair.as_rule() != Rule::EOI)
65-
.map(parse_value)
66-
.collect()
67-
})
61+
pub fn parse(format: &str) -> Result<Vec<FormatElement>, Box<Error<Rule>>> {
62+
IdentParser::parse(Rule::expression, format)
63+
.map(|pairs| {
64+
pairs
65+
.take_while(|pair| pair.as_rule() != Rule::EOI)
66+
.map(parse_value)
67+
.collect()
68+
})
69+
.map_err(Box::new)
6870
}

src/formatter/string_formatter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ type StyleVariableMapType<'a> =
3535
#[derive(Debug, Clone, PartialEq, Eq)]
3636
pub enum StringFormatterError {
3737
Custom(String),
38-
Parse(PestError<Rule>),
38+
Parse(Box<PestError<Rule>>),
3939
}
4040

4141
impl fmt::Display for StringFormatterError {
4242
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4343
match self {
44-
Self::Custom(error) => write!(f, "{}", error),
45-
Self::Parse(error) => write!(f, "{}", error),
44+
Self::Custom(error) => write!(f, "{error}"),
45+
Self::Parse(error) => write!(f, "{error}"),
4646
}
4747
}
4848
}
@@ -538,7 +538,7 @@ mod tests {
538538

539539
let formatter = StringFormatter::new(FORMAT_STR)
540540
.unwrap()
541-
.map(|variable| Some(Ok(format!("${{{}}}", variable))));
541+
.map(|variable| Some(Ok(format!("${{{variable}}}"))));
542542
let result = formatter.parse(None, None).unwrap();
543543
let mut result_iter = result.iter();
544544
match_next!(result_iter, "${env:PWD}", None);

src/formatter/version.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'a> VersionFormatter<'a> {
7171
Ok(formatted) => Some(formatted),
7272
Err(error) => {
7373
log::warn!("Error formatting `{}` version:\n{}", module_name, error);
74-
Some(format!("v{}", version))
74+
Some(format!("v{version}"))
7575
}
7676
}
7777
}

src/init/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ impl StarshipPath {
4444
fn sprint_pwsh(&self) -> io::Result<String> {
4545
self.str_path()
4646
.map(|s| s.replace('\'', "''"))
47-
.map(|s| format!("'{}'", s))
47+
.map(|s| format!("'{s}'"))
4848
}
4949
/// Command Shell specific path escaping
5050
fn sprint_cmdexe(&self) -> io::Result<String> {
51-
self.str_path().map(|s| format!("\"{}\"", s))
51+
self.str_path().map(|s| format!("\"{s}\""))
5252
}
5353
fn sprint_posix(&self) -> io::Result<String> {
5454
// On non-Windows platform, return directly.
@@ -229,7 +229,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> {
229229

230230
fn print_script(script: &str, path: &str) {
231231
let script = script.replace("::STARSHIP::", path);
232-
print!("{}", script);
232+
print!("{script}");
233233
}
234234

235235
/* GENERAL INIT SCRIPT NOTES

src/logger.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Default for StarshipLogger {
2929
});
3030

3131
fs::create_dir_all(&log_dir)
32-
.unwrap_or_else(|err| panic!("Unable to create log dir {:?}: {:?}!", log_dir, err));
32+
.unwrap_or_else(|err| panic!("Unable to create log dir {log_dir:?}: {err:?}!"));
3333
let session_log_file = log_dir.join(format!(
3434
"session_{}.log",
3535
env::var("STARSHIP_SESSION_KEY").unwrap_or_default()
@@ -96,12 +96,12 @@ impl log::Log for StarshipLogger {
9696
})
9797
.unwrap_or_else(|err: std::io::Error| {
9898
panic!(
99-
"Unable to open session log file {:?}: {:?}!",
100-
self.log_file_path, err
99+
"Unable to open session log file {:?}: {err:?}!",
100+
self.log_file_path
101101
)
102102
})
103103
.lock()
104-
.map(|mut file| writeln!(file, "{}", to_print))
104+
.map(|mut file| writeln!(file, "{to_print}"))
105105
.expect("Log file writer mutex was poisoned!")
106106
.expect("Unable to write to the log file!");
107107
}

src/modules/aws.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn get_profile_config<'a>(
6666
profile: &Option<Profile>,
6767
) -> Option<&'a ini::Properties> {
6868
match profile {
69-
Some(profile) => config.section(Some(format!("profile {}", profile))),
69+
Some(profile) => config.section(Some(format!("profile {profile}"))),
7070
None => config.section(Some("default")),
7171
}
7272
}
@@ -701,7 +701,7 @@ aws_secret_access_key=dummy
701701
"30m2s", "30m1s", "30m", "29m59s", "29m58s", "29m57s", "29m56s", "29m55s",
702702
];
703703
let possible_values = possible_values.map(|duration| {
704-
let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{}] ", duration);
704+
let segment_colored = format!("☁️ astronauts (ap-northeast-2) [{duration}] ");
705705
Some(format!(
706706
"on {}",
707707
Color::Yellow.bold().paint(segment_colored)
@@ -762,7 +762,7 @@ aws_secret_access_key=dummy
762762
"on {}",
763763
Color::Yellow
764764
.bold()
765-
.paint(format!("☁️ astronauts (ap-northeast-2) [{}] ", symbol))
765+
.paint(format!("☁️ astronauts (ap-northeast-2) [{symbol}] "))
766766
));
767767

768768
assert_eq!(expected, actual);

src/modules/azure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn get_config_file_location(context: &Context) -> Option<PathBuf> {
8989
fn parse_json(json_file_path: &Path) -> Option<JValue> {
9090
let mut buffer: Vec<u8> = Vec::new();
9191

92-
let json_file = File::open(&json_file_path).ok()?;
92+
let json_file = File::open(json_file_path).ok()?;
9393
let mut reader = BufReader::new(json_file);
9494
reader.read_to_end(&mut buffer).ok()?;
9595

src/modules/container.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ mod tests {
141141
containerenv.push(".containerenv");
142142
let mut file = std::fs::File::create(&containerenv)?;
143143
if let Some(name) = name {
144-
file.write_all(format!("image=\"{}\"\n", name).as_bytes())?;
144+
file.write_all(format!("image=\"{name}\"\n").as_bytes())?;
145145
}
146146

147147
// The output of the module

0 commit comments

Comments
 (0)