Skip to content

Commit

Permalink
refactor(clippy): apply clippy-suggested fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gibfahn committed Apr 20, 2024
1 parent 59673d3 commit f1ba666
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn add_builtin_env_vars(env: &mut HashMap<String, String>) -> Result<()> {
#[derive(Error, Debug, Display)]
/// Errors thrown by this file.
pub enum EnvError {
/// Env lookup error, please define '{var:?}' in your up.yaml:"
/// Env lookup error, please define `{var:?}` in your up.yaml:"
EnvLookup {
/// Missing env var.
var: String,
Expand Down
4 changes: 2 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use thiserror::Error;
#[derive(Error, Debug, Display)]
/// Errors thrown by the Up Crate.
pub enum UpError {
/// Failed to delete '{path}'.
/// Failed to delete `{path}`.
DeleteError {
/// Path we tried to delete.
path: Utf8PathBuf,
/// Source error.
source: io::Error,
},
/// IO Failure for path '{path}'.
/// IO Failure for path `{path}`.
IoError {
/// Path we tried to write to.
path: Utf8PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion src/generate/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn parse_git_config(
pub enum GenerateGitError {
/// Invalid UTF-8.
InvalidUtf8,
/// Invalid remote '{name}'.
/// Invalid remote `{name}`.
InvalidRemote {
/// Remote name.
name: String,
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
clippy::module_name_repetitions,
// Not usually worth fixing.
clippy::needless_pass_by_value,
// Don't error in stable about nightly-only lints.
unknown_lints,
// https://github.com/yaahc/displaydoc/issues/46
non_local_definitions,
)]

use crate::config::UpConfig;
Expand Down
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
use tracing::debug;
use tracing::info;
use tracing::level_filters::LevelFilter;
use tracing::trace;
use tracing::warn;
use tracing::Level;
use tracing_error::ErrorLayer;
use tracing_subscriber::filter::EnvFilter;
use tracing_subscriber::prelude::*;
use up_rs::log;
use up_rs::opts::Opts;

/// Env vars to avoid printing when we log the current environment.
Expand All @@ -37,6 +38,7 @@ const IGNORED_ENV_VARS: [&str; 1] = [
];

// TODO(gib): Return correct exit codes using https://docs.rs/exitcode/1.1.2/exitcode/.
#[allow(clippy::cognitive_complexity)] // This function seems fairly simple to me.
fn main() -> Result<()> {
// Get starting time.
let now = Instant::now();
Expand Down Expand Up @@ -76,11 +78,12 @@ fn main() -> Result<()> {

// No need to log the time we took to run by default unless it actually took some time.
let now_elapsed = now.elapsed();
if now_elapsed > Duration::from_secs(10) {
info!("Up-rs ran successfully in {now_elapsed:?}");
let level = if now_elapsed > Duration::from_secs(10) {
Level::INFO
} else {
debug!("Up-rs ran successfully in {now_elapsed:?}");
}
Level::DEBUG
};
log!(level, "Up-rs ran successfully in {now_elapsed:?}");
trace!("Finished up.");
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub(crate) struct RunOptions {
#[clap(short = 'f', long, value_hint = ValueHint::Url)]
pub(crate) fallback_url: Option<String>,
/// Fallback path inside the git repo to get the config.
/// The default path assumes your fallback_url points to a dotfiles repo
/// The default path assumes your `fallback_url` points to a dotfiles repo
/// that is linked into ~.
#[clap(
short = 'p',
Expand Down Expand Up @@ -343,9 +343,9 @@ pub struct DefaultsWriteOptions {
If you want to append to an existing array or dictionary, use `...` as an array value, or `...:...` as a dictionary entry, to represent the existing items in the array.
If there are duplicates, the first entry will be preserved.
So if the array contained ["a", "foo", "b", "bar", "c"], and you write ["foo", "...", "bar", "baz"], you would end up with ["foo", "a", "b", "bar", "c", "baz"]
So if the array contained `["a", "foo", "b", "bar", "c"]`, and you write `["foo", "...", "bar", "baz"]`, you would end up with `["foo", "a", "b", "bar", "c", "baz"]`
Similarly if the dict contained {"a": 1, "foo": 2, "b": 3, "bar": 4, "c": 5}, and you write {"foo": 6 "...":"...", "bar": 7, "baz": 8}, you would end up with {"a": 1, "foo": 6, "b": 3, "bar": 4, "c": 5, "baz": 8}
Similarly if the dict contained `{"a": 1, "foo": 2, "b": 3, "bar": 4, "c": 5}`, and you write `{"foo": 6 "...":"...", "bar": 7, "baz": 8}`, you would end up with `{"a": 1, "foo": 6, "b": 3, "bar": 4, "c": 5, "baz": 8}`
*/
pub(crate) value: Option<String>,
}
21 changes: 11 additions & 10 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ fn create_task_tempdir(temp_dir: &Utf8Path, task_name: &str) -> Result<Utf8PathB
Ok(task_tempdir)
}

#[allow(clippy::doc_markdown)]
#[derive(Error, Debug, Display)]
/// Errors thrown by this file.
pub enum TaskError {
/// Task '{name}' {lib} failed.
/// Task `{name}` {lib} failed.
TaskError {
/// Source error.
source: color_eyre::eyre::Error,
Expand All @@ -339,21 +340,21 @@ pub enum TaskError {
/// The task name.
name: String,
},
/// Error walking directory '{path}':
/// Error walking directory `{path}`:
ReadDir {
/// The path we failed to walk.
path: Utf8PathBuf,
/// Source error.
source: io::Error,
},
/// Error reading file '{path}':
/// Error reading file `{path}`:
ReadFile {
/// The path we failed to read.
path: Utf8PathBuf,
/// Source error.
source: io::Error,
},
/// Env lookup error, please define '{var}' in your up.yaml:"
/// Env lookup error, please define `{var}` in your up.yaml:"
EnvLookup {
/// The env var we couldn't find.
var: String,
Expand All @@ -362,13 +363,13 @@ pub enum TaskError {
},
/// Commmand was empty.
EmptyCmd,
/// Task '{name}' had no run command.
/// Task `{name}` had no run command.
MissingCmd {
/// The task name.
name: String,
},
/**
Task '{name}' {command_type} failed.Command: {cmd:?}.{suggestion}
Task `{name}` {command_type} failed.Command: {cmd:?}.{suggestion}
*/
CmdFailed {
/// The type of command that failed (check or run).
Expand All @@ -383,7 +384,7 @@ pub enum TaskError {
suggestion: String,
},
/**
Task '{name}' {command_type} failed with exit code {code}. Command: {cmd:?}.
Task `{name}` {command_type} failed with exit code {code}. Command: {cmd:?}.
Output: {output_file}
*/
CmdNonZero {
Expand All @@ -399,7 +400,7 @@ pub enum TaskError {
output_file: Utf8PathBuf,
},
/**
Task '{name}' {command_type} was terminated. Command: {cmd:?}, output: {output_file}.
Task `{name}` {command_type} was terminated. Command: {cmd:?}, output: {output_file}.
Output: {output_file}
*/
CmdTerminated {
Expand All @@ -414,7 +415,7 @@ pub enum TaskError {
},
/// Unexpectedly empty option found.
UnexpectedNone,
/// Invalid yaml at '{path}':
/// Invalid yaml at `{path}`:
InvalidYaml {
/// Path that contained invalid yaml.
path: Utf8PathBuf,
Expand All @@ -423,7 +424,7 @@ pub enum TaskError {
},
/// Unable to calculate the current user's home directory.
MissingHomeDir,
/// Env lookup error, please define '{var}' in your up.yaml
/// Env lookup error, please define `{var}` in your up.yaml
ResolveEnv {
/// Env var we couldn't find.
var: String,
Expand Down
9 changes: 5 additions & 4 deletions src/tasks/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub(crate) fn run(config: DefaultsConfig, up_dir: &Utf8Path) -> Result<TaskStatu
}
}

#[allow(clippy::doc_markdown)]
#[derive(Error, Debug, Display)]
/// Errors thrown by this file.
pub enum DefaultsError {
Expand Down Expand Up @@ -190,7 +191,7 @@ pub enum DefaultsError {
status: ExitStatus,
},

/// Unable to create dir at: {path}.
/// Unable to create dir at: `{path}`.
DirCreation {
/// Dir we failed to create.
path: Utf8PathBuf,
Expand All @@ -201,8 +202,8 @@ pub enum DefaultsError {
/**
Unable to copy file.
From: {from_path}
To: {to_path}
From: `{from_path}`
To: `{to_path}`
*/
FileCopy {
/// Path we tried to copy from.
Expand All @@ -213,7 +214,7 @@ pub enum DefaultsError {
source: std::io::Error,
},

/// Failed to read bytes from path {path}.
/// Failed to read bytes from path `{path}`.
FileRead {
/// File we tried to read.
path: Utf8PathBuf,
Expand Down
13 changes: 7 additions & 6 deletions src/tasks/git/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ use git2::MergePreference;
use std::io;
use thiserror::Error;

#[allow(clippy::doc_markdown)]
#[derive(Error, Debug, Display)]
/// Errors thrown by the Git task.
pub enum GitError {
/// Failed to update git repo at '{path}'.
/// Failed to update git repo at `{path}`.
GitUpdate {
/// The path we failed to update.
path: Utf8PathBuf,
},
/// Failed to create directory '{path}'
/// Failed to create directory `{path}`
CreateDirError {
/// The path we failed to create.
path: Utf8PathBuf,
Expand Down Expand Up @@ -48,7 +49,7 @@ pub enum GitError {
/// Git status of uncommitted changes.
status: String,
},
/// Fetch failed for remote '{remote}'.{extra_info}
/// Fetch failed for remote `{remote}`.{extra_info}
FetchFailed {
/// Git remote name.
remote: String,
Expand All @@ -57,19 +58,19 @@ pub enum GitError {
/// Extra info or hints about why fetch failed.
extra_info: String,
},
/// Couldn't find oid for branch '{branch_name}'.
/// Couldn`t find oid for branch `{branch_name}`.
NoOidFound {
/// Git branch name.
branch_name: String,
},
/// Couldn't convert oid '{oid}' into a commit.
/// Couldn`t convert oid `{oid}` into a commit.
NoCommitFound {
/// Reference name.
oid: String,
/// Source error.
source: git2::Error,
},
/// Failed to merge {merge_rev} ({merge_ref}) into {branch}.
/// Failed to merge `{merge_rev}` (`{merge_ref}`) into `{branch}`.
Merge {
/// Git branch.
branch: String,
Expand Down
6 changes: 3 additions & 3 deletions src/tasks/git/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ fn set_up_remote(repo: &Repository, remote_config: &GitRemote) -> Result<bool> {
let mut host = "parse error".to_owned();
let mut path = "parse error".to_owned();
if let Ok(parsed) = parsed_result {
protocol = parsed.scheme().to_owned();
parsed.scheme().clone_into(&mut protocol);
if let Some(host_str) = parsed.host_str() {
host = host_str.to_owned();
host_str.clone_into(&mut host);
}
path = parsed.path().trim_matches('/').to_owned();
parsed.path().trim_matches('/').clone_into(&mut path);
}

let base = if cfg!(target_os = "macos") { format!("\n\n - Check that this command returns 'osxkeychain':\n \
Expand Down
16 changes: 8 additions & 8 deletions src/tasks/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,42 +290,42 @@ fn link_path(
#[derive(Error, Debug, Display)]
/// Errors thrown by this file.
pub enum LinkError {
/// {name} directory '{path}' should exist and be a directory.
/// {name} directory `{path}` should exist and be a directory.
MissingDir {
/// Directory name.
name: String,
/// Directory path.
path: Utf8PathBuf,
},
/// Error canonicalizing {path}.
/// Error canonicalizing `{path}`.
CanonicalizeError {
/// Path we failed to canonicalize.
path: Utf8PathBuf,
/// Source error.
source: io::Error,
},
/// Failed to create directory '{path}'
/// Failed to create directory `{path}`
CreateDirError {
/// Directory path we failed to create.
path: Utf8PathBuf,
/// Source error.
source: io::Error,
},
/// Failed to delete '{path}'.
/// Failed to delete `{path}`.
DeleteError {
/// Path we failed to delete.
path: Utf8PathBuf,
/// Source error.
source: io::Error,
},
/// Failure for path '{path}'.
/// Failure for path `{path}`.
IoError {
/// Path we got an IO error for.
path: Utf8PathBuf,
/// Source error.
source: io::Error,
},
/// Failed to rename from '{from_path}' to '{to_path}'.
/// Failed to rename from `{from_path}` to `{to_path}`.
RenameError {
/// Existing name.
from_path: Utf8PathBuf,
Expand All @@ -334,7 +334,7 @@ pub enum LinkError {
/// Source error.
source: io::Error,
},
/// Failed to symlink from '{from_path}' to '{to_path}'.
/// Failed to symlink from `{from_path}` to `{to_path}`.
SymlinkError {
/// Real file we were trying to symlink from.
from_path: Utf8PathBuf,
Expand All @@ -343,7 +343,7 @@ pub enum LinkError {
/// Source error.
source: io::Error,
},
/// Path '{path}' should have a parent directory.
/// Path `{path}` should have a parent directory.
MissingParentDir {
/// Path that doesn't have a parent dir.
path: Utf8PathBuf,
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ const fn default_false() -> bool {
/// Shell commands we run.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CommandType {
/// run_if_cmd field in the yaml.
/// `run_if_cmd` field in the yaml.
RunIf,
/// run_cmd field in the yaml.
/// `run_cmd` field in the yaml.
Run,
}

Expand Down
Loading

0 comments on commit f1ba666

Please sign in to comment.