Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Cleanup various code style warnings #769

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Command for AuthCommand {
String::from("auth")
}
fn app(&self) -> clap::Command {
clap::Command::new(&self.name())
clap::Command::new(self.name())
.version("1.0")
.about("configure authentication tokens")
.long_about("Configures the authentication tokens used by Git-Tool to create and manage your remote repositories.")
Expand Down Expand Up @@ -75,7 +75,7 @@ impl CommandRunnable for AuthCommand {

core.keychain().set_token(service, &token)?;

writeln!(core.output(), "Access Token set for service '{}'", service)?;
writeln!(core.output(), "Access Token set for service '{service}'")?;
if let Some(online_service) =
crate::online::services().iter().find(|s| s.handles(svc))
{
Expand Down
2 changes: 1 addition & 1 deletion src/commands/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Command for CompleteCommand {
String::from("complete")
}
fn app(&self) -> clap::Command {
clap::Command::new(&self.name())
clap::Command::new(self.name())
.version("1.0")
.about("provides command auto-completion")
.long_about("Provides realtime command and argument auto-completion for Git-Tool when using `git-tool shell-init`.")
Expand Down
22 changes: 9 additions & 13 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl CommandRunnable for ConfigCommand {
let entries = registry.get_entries(core).await?;
let mut output = core.output();
for entry in entries {
writeln!(output, "{}", entry)?;
writeln!(output, "{entry}")?;
}
}
Some(("add", args)) => {
Expand Down Expand Up @@ -170,22 +170,18 @@ impl CommandRunnable for ConfigCommand {
}
None => match core.config().get_alias(alias) {
Some(repo) => {
writeln!(core.output(), "{} = {}", alias, repo)?;
writeln!(core.output(), "{alias} = {repo}")?;
}
None => {
writeln!(
core.output(),
"No alias exists with the name '{}'",
alias
)?;
writeln!(core.output(), "No alias exists with the name '{alias}'")?;
}
},
}
}
None => {
let mut output = core.output();
for (alias, repo) in core.config().get_aliases() {
writeln!(output, "{} = {}", alias, repo)?;
writeln!(output, "{alias} = {repo}")?;
}
}
},
Expand All @@ -204,7 +200,7 @@ impl CommandRunnable for ConfigCommand {
}
}
Some(invalid) => {
writeln!(core.output(), "Cannot set the feature flag {} to {} because only 'true' and 'false' are valid settings.", flag, invalid)?;
writeln!(core.output(), "Cannot set the feature flag '{flag}' to '{invalid}' because only 'true' and 'false' are valid settings.")?;
return Ok(1);
}
None => {
Expand Down Expand Up @@ -432,7 +428,7 @@ mod tests {

let console = crate::console::mock();
let core = Core::builder()
.with_config_file(&temp.path().join("config.yml"))
.with_config_file(temp.path().join("config.yml"))
.expect("the config should be loaded")
.with_console(console.clone())
.build();
Expand Down Expand Up @@ -548,7 +544,7 @@ aliases:
.unwrap();

let core = Core::builder()
.with_config_file(&temp.path().join("config.yml"))
.with_config_file(temp.path().join("config.yml"))
.expect("the config should be loaded")
.with_null_console()
.build();
Expand Down Expand Up @@ -586,7 +582,7 @@ aliases:
.unwrap();

let core = Core::builder()
.with_config_file(&temp.path().join("config.yml"))
.with_config_file(temp.path().join("config.yml"))
.expect("the config should be loaded")
.with_null_console()
.build();
Expand Down Expand Up @@ -654,7 +650,7 @@ features:
.unwrap();

let core = Core::builder()
.with_config_file(&temp.path().join("config.yml"))
.with_config_file(temp.path().join("config.yml"))
.expect("the config should be loaded")
.with_null_console()
.build();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Command for DoctorCommand {
}

fn app(&self) -> clap::Command {
clap::Command::new(&self.name())
clap::Command::new(self.name())
.version("1.0")
.about("checks that your environment is configured correctly for Git-Tool")
.long_about("Runs a series of checks to ensure that the environment is ready to run the application")
Expand Down
4 changes: 2 additions & 2 deletions src/commands/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub fn get_launch_app<'a, S: AsRef<str> + std::fmt::Debug + std::fmt::Display +
LaunchTarget::AppAndTarget(app, first.as_ref())
} else {
LaunchTarget::Err(errors::user(
format!("Could not find application with name '{}'.", first).as_str(),
format!("Make sure that you are using an application which is present in your configuration file, or install it with 'git-tool config add apps/{}'.", first).as_str()))
format!("Could not find application with name '{first}'.").as_str(),
format!("Make sure that you are using an application which is present in your configuration file, or install it with 'git-tool config add apps/{first}'.").as_str()))
}
}
(Some(first), None) => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CommandRunnable for IgnoreCommand {
let languages = gitignore::list(core).await?;

for lang in languages {
writeln!(core.output(), "{}", lang)?;
writeln!(core.output(), "{lang}")?;
}
}
Some(languages) => {
Expand Down Expand Up @@ -100,7 +100,7 @@ mod tests {
.build();

let cmd = IgnoreCommand {};
let args = cmd.app().get_matches_from(&["ignore"]);
let args = cmd.app().get_matches_from(["ignore"]);

match cmd.run(&core, &args).await {
Ok(_) => {}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ impl Command for ListCommand {
String::from("list")
}
fn app(&self) -> clap::Command {
clap::Command::new(&self.name())
clap::Command::new(self.name())
.version("1.0")
.visible_aliases(&["ls", "ll"])
.visible_aliases(["ls", "ll"])
.about("list your repositories")
.after_help("Gets the list of repositories managed by Git-Tool. These repositories can be opened using the `git-tool open` command.")
.arg(Arg::new("filter")
Expand Down Expand Up @@ -127,7 +127,7 @@ mod tests {
async fn run_normal() {
let console = Arc::new(MockConsoleProvider::new());
let core = Core::builder()
.with_config_for_dev_directory(&get_dev_dir())
.with_config_for_dev_directory(get_dev_dir())
.with_console(console.clone())
.build();

Expand Down
4 changes: 2 additions & 2 deletions src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ impl Command for NewCommand {
}

fn app(&self) -> clap::Command {
clap::Command::new(&self.name())
clap::Command::new(self.name())
.version("1.0")
.about("creates a new repository")
.visible_aliases(&["n", "create"])
.visible_aliases(["n", "create"])
.long_about("Creates a new repository with the provided name.")
.arg(
Arg::new("repo")
Expand Down
2 changes: 1 addition & 1 deletion src/commands/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Command for OpenCommand {
fn app(&self) -> clap::Command {
clap::Command::new(self.name())
.version("1.0")
.visible_aliases(&["o", "run"])
.visible_aliases(["o", "run"])
.about("opens a repository using an application defined in your config")
.long_about("This command launches an application defined in your configuration within the specified repository. You can specify any combination of alias, app and repo. Aliases take precedence over repos, which take precedence over apps. When specifying an app, it should appear before the repo/alias parameter. If you are already inside a repository, you can specify only an app and it will launch in the context of the current repo.

Expand Down
2 changes: 1 addition & 1 deletion src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl CommandRunnable for PruneCommand {
if !matches.get_flag("yes") {
writeln!(core.output(), "The following branches will be removed:")?;
for branch in to_remove.iter() {
writeln!(core.output(), " {}", branch)?;
writeln!(core.output(), " {branch}")?;
}
writeln!(core.output())?;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Command for RemoveCommand {
fn app(&self) -> clap::Command {
clap::Command::new(self.name())
.version("1.0")
.visible_aliases(&["rm"])
.visible_aliases(["rm"])
.about("removes a repository from your local machine")
.long_about("This command will remove the specified repository from your local machine. It requires that the repository name be provided in fully-qualified form.")
.arg(Arg::new("repo")
Expand Down
2 changes: 1 addition & 1 deletion src/commands/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl Command for ServicesCommand {
String::from("services")
}
fn app(&self) -> clap::Command {
clap::Command::new(&self.name())
clap::Command::new(self.name())
.version("1.0")
.about("list services which can be used with Git-Tool")
.long_about("Gets the list of services that you have added to your configuration file. These services are responsible for hosting your Git repositories.")
Expand Down
4 changes: 2 additions & 2 deletions src/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl SetupCommand {
"Enter a directory to hold your repositories{}: ",
default_dir
.clone()
.map(|v| format!(" [{}]", v))
.map(|v| format!(" [{v}]"))
.unwrap_or_else(|| "".into())
),
|line| {
Expand All @@ -125,7 +125,7 @@ impl SetupCommand {
Ok(_) => { true },
Err(err) if err.kind() == ErrorKind::NotFound => { true },
Err(err) => {
writeln!(core.output(), " [!] That doesn't look like a valid path to us, please try again ({}).", err).unwrap_or_default();
writeln!(core.output(), " [!] That doesn't look like a valid path to us, please try again ({err}).").unwrap_or_default();
false
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/shell_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ where {
Some((name, matches)) => {
let shells = get_shells();
let shell = shells.iter().find(|s| s.get_name() == name).ok_or_else(|| errors::user(
&format!("The shell '{}' is not currently supported by Git-Tool.", name),
&format!("The shell '{name}' is not currently supported by Git-Tool."),
"Make sure you're using a supported shell, or submit a PR on GitHub to add support for your shell."
))?;

Expand Down
4 changes: 2 additions & 2 deletions src/commands/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Command for SwitchCommand {
clap::Command::new(self.name())
.version("1.0")
.about("switches to the specified branch.")
.visible_aliases(&["sw", "branch", "b", "br"])
.visible_aliases(["sw", "branch", "b", "br"])
.long_about(
"This command switches to the specified branch within the current repository.",
)
Expand Down Expand Up @@ -59,7 +59,7 @@ impl CommandRunnable for SwitchCommand {
.unique()
.sorted()
{
println!("{}", branch);
writeln!(core.output(), "{branch}")?;
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl Command for UpdateCommand {
String::from("update")
}
fn app(&self) -> clap::Command {
clap::Command::new(&self.name())
clap::Command::new(self.name())
.version("1.0")
.about("updates Git-Tool automatically by fetching the latest release from GitHub")
.long_about("Allows you to update Git-Tool to the latest version, or a specific version, automatically.")
Expand Down
4 changes: 2 additions & 2 deletions src/completion/completer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ impl Completer {
}
let mut out = self.console.output();
if has_whitespace(completion) {
writeln!(out, "'{}'", completion).unwrap_or_default();
writeln!(out, "'{completion}'").unwrap_or_default();
} else {
writeln!(out, "{}", completion).unwrap_or_default();
writeln!(out, "{completion}").unwrap_or_default();
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ impl Config {

match &self.schema {
Some(schema) => Ok(format!(
"# yaml-language-server: $schema={}\n{}",
schema, config
"# yaml-language-server: $schema={schema}\n{config}",
)),
None => Ok(config),
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ impl HttpClient for TrueHttpClient {

if !response.status().is_success() {
tracing::span::Span::current()
.record("otel.status_code", &2_u32)
.record("otel.status_code", 2_u32)
.record(
"otel.status_message",
&response.status().canonical_reason().unwrap_or("<none>"),
response.status().canonical_reason().unwrap_or("<none>"),
);
}

tracing::span::Span::current()
.record("http.status_code", &response.status().as_u16())
.record("http.status_code", response.status().as_u16())
.record(
"http.response_content_length",
&response.content_length().unwrap_or(0),
response.content_length().unwrap_or(0),
);

Ok(response)
Expand Down
2 changes: 1 addition & 1 deletion src/core/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Prompter {
let mut reader = self.console.input();

for _i in 0..3 {
write!(writer, "{}", message)?;
write!(writer, "{message}")?;
writer.flush()?;

let line = Self::read_line(&mut reader)?;
Expand Down
4 changes: 2 additions & 2 deletions src/core/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl TrueResolver {
"Current directory is not a valid repository.",
&format!("Make sure that you are currently within a repository contained within your development directory ('{}').", dev_dir.display())))?;
let svc_name = svc.as_os_str().to_string_lossy().to_string();
repo_from_svc_and_path(&self.config, Some(svc_name), relative_path.strip_prefix(&svc).unwrap_or(relative_path), false)
repo_from_svc_and_path(&self.config, Some(svc_name), relative_path.strip_prefix(svc).unwrap_or(relative_path), false)
},
Err(e) => Err(errors::system_with_internal(
"We were unable to determine the repository's fully qualified name.",
Expand Down Expand Up @@ -244,7 +244,7 @@ fn repo_from_svc_and_path(
Some(svc) => match config.get_service(&svc) {
Some(svc) => Ok(svc),
None => Err(errors::user(
&format!("The service '{}' does not exist.", svc),
&format!("The service '{svc}' does not exist."),
"Please check that you have provided the correct service name, and that the service is present in your Git-Tool config."
))
},
Expand Down
2 changes: 1 addition & 1 deletion src/core/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ macro_rules! map(
pub fn render(tmpl: &str, context: Value) -> Result<String, errors::Error> {
debug!("Rendering template '{}' with context {}", tmpl, context);
template(tmpl, context).map_err(|e| errors::user_with_internal(
format!("We couldn't render your template '{}'.", tmpl).as_str(),
format!("We couldn't render your template '{tmpl}'.").as_str(),
"Check that your template follows the Go template syntax here: https://golang.org/pkg/text/template/",
errors::detailed_message(&e.to_string())))
}
Expand Down
2 changes: 1 addition & 1 deletion src/errors/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl From<keyring::Error> for Error {
e => user_with_internal(
"A problem occurred while trying to access the secure token store.",
"This might indicate that you haven't configured an access token yet, which you can do with `git-tool auth github.com`. It may also indicate that there is an issue with your system secure token store. Please open a GitHub issue if you cannot resolve this.",
detailed_message(&format!("{:?}", e)))
detailed_message(&format!("{e:?}")))
}
}
}
8 changes: 4 additions & 4 deletions src/git/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod tests {
.await
.expect("should be able to get the branches list");

println!("{:?}", branch);
println!("{branch:?}");

assert!(
branch.iter().any(|x| x == "main"),
Expand Down Expand Up @@ -259,7 +259,7 @@ mod tests {
.await
.expect("should be able to get the branches list");

println!("{:?}", default_branch);
println!("{default_branch:?}");

assert_eq!(
default_branch, "main",
Expand Down Expand Up @@ -318,7 +318,7 @@ mod tests {
.await
.expect("should be able to get the branches list");

println!("{:?}", branches);
println!("{branches:?}");

assert!(
!branches.iter().any(|x| x == "main"),
Expand Down Expand Up @@ -386,7 +386,7 @@ mod tests {
.await
.expect("should be able to get the branches list");

println!("{:?}", branch);
println!("{branch:?}");

assert!(
branch.iter().any(|x| x == "main"),
Expand Down
Loading