Skip to content

Commit

Permalink
Apply Clippy changes (#374)
Browse files Browse the repository at this point in the history
Feel free to close if not helpful...
  • Loading branch information
max-sixty committed Jun 3, 2023
1 parent 4c0607a commit 7bd287e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cargo-insta/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Package {
roots.sort_by_key(|x| x.as_os_str().len());
let mut reduced_roots = vec![];
for root in roots {
if !reduced_roots.iter().any(|x| root.starts_with(&x)) {
if !reduced_roots.iter().any(|x| root.starts_with(x)) {
reduced_roots.push(root);
}
}
Expand Down
22 changes: 9 additions & 13 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ fn handle_target_args(target_args: &TargetArgs) -> Result<LocationInfo<'_>, Box<
target_args.manifest_path.as_ref(),
) {
(Some(_), Some(_)) => {
return Err(err_msg(format!(
"both manifest-path and workspace-root provided."
)))
return Err(err_msg("both manifest-path and workspace-root provided.".to_string()))
}
(None, Some(manifest)) => (None, Some(Cow::Borrowed(manifest))),
(Some(root), manifest_path) => {
Expand All @@ -370,7 +368,7 @@ fn handle_target_args(target_args: &TargetArgs) -> Result<LocationInfo<'_>, Box<
};

if let Some(workspace_root) = workspace_root {
let tool_config = ToolConfig::from_workspace(&workspace_root)?;
let tool_config = ToolConfig::from_workspace(workspace_root)?;
Ok(LocationInfo {
workspace_root: workspace_root.to_owned(),
packages: None,
Expand Down Expand Up @@ -429,7 +427,7 @@ fn process_snapshots(
) -> Result<(), Box<dyn Error>> {
let term = Term::stdout();

let (mut snapshot_containers, roots) = load_snapshot_containers(&loc)?;
let (mut snapshot_containers, roots) = load_snapshot_containers(loc)?;

let snapshot_count = snapshot_containers.iter().map(|x| x.0.len()).sum();

Expand All @@ -455,7 +453,7 @@ fn process_snapshots(
let snapshot_file = snapshot_container.snapshot_file().map(|x| x.to_path_buf());
for snapshot_ref in snapshot_container.iter_snapshots() {
// if a filter is provided, check if the snapshot reference is included
if let Some(ref filter) = snapshot_filter {
if let Some(filter) = snapshot_filter {
let key = if let Some(line) = snapshot_ref.line {
format!("{}:{}", target_file.display(), line)
} else {
Expand All @@ -479,7 +477,7 @@ fn process_snapshots(
snapshot_ref.line,
num,
snapshot_count,
snapshot_file.as_ref().map(|x| x.as_path()),
snapshot_file.as_deref(),
&mut show_info,
&mut show_diff,
)?,
Expand Down Expand Up @@ -744,7 +742,7 @@ fn handle_unreferenced_snapshots(
}
}

fs::remove_file(&path).ok();
fs::remove_file(path).ok();

if !encountered_any {
eprintln!("{}: no unreferenced snapshots found", style("info").bold());
Expand Down Expand Up @@ -961,12 +959,10 @@ fn pending_snapshots_cmd(cmd: PendingSnapshotsCommand) -> Result<(), Box<dyn Err
SnapshotKey::NamedSnapshot { path: &target_file }
};
println!("{}", serde_json::to_string(&info).unwrap());
} else if is_inline {
println!("{}:{}", target_file.display(), snapshot_ref.line.unwrap());
} else {
if is_inline {
println!("{}:{}", target_file.display(), snapshot_ref.line.unwrap());
} else {
println!("{}", target_file.display());
}
println!("{}", target_file.display());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cargo-insta/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use console::style;

fn main() {
if let Err(err) = cli::run() {
let exit_code = if let Some(ref exit) = err.downcast_ref::<utils::QuietExit>() {
let exit_code = if let Some(exit) = err.downcast_ref::<utils::QuietExit>() {
exit.0
} else {
println!("{} {}", style("error:").red().bold(), err);
Expand Down
6 changes: 3 additions & 3 deletions cargo-insta/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn find_snapshots<'a>(
extensions: &'a [&'a str],
flags: FindFlags,
) -> impl Iterator<Item = Result<SnapshotContainer, Box<dyn Error>>> + 'a {
make_snapshot_walker(&root, extensions, flags)
make_snapshot_walker(root, extensions, flags)
.filter_map(|e| e.ok())
.filter_map(move |e| {
let fname = e.file_name().to_string_lossy();
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn make_deletion_walker(
known_packages: Option<&[Package]>,
selected_package: Option<&str>,
) -> Walk {
let roots: HashSet<_> = if let Some(ref packages) = known_packages {
let roots: HashSet<_> = if let Some(packages) = known_packages {
packages
.iter()
.filter_map(|x| {
Expand Down Expand Up @@ -120,7 +120,7 @@ pub fn make_deletion_walker(

// We always want to skip target even if it was not excluded by
// ignore files.
if entry.path().file_name() == Some(&OsStr::new("target"))
if entry.path().file_name() == Some(OsStr::new("target"))
&& roots.contains(canonicalized.parent().unwrap())
{
return false;
Expand Down

0 comments on commit 7bd287e

Please sign in to comment.