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

Apply Clippy changes #374

Merged
merged 1 commit into from
Jun 3, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -956,12 +954,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