From 9e638ea26ae6b1372d93ac371963d644130e9419 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 25 Nov 2024 12:17:21 -0500 Subject: [PATCH] fix: don't move modules back to their "proper" location The function modified here is meant to return `nil` when a file shouldn't be removed. This was returning the "proper location" when it should have just been returning `nil`, to indicate not to move the file. fixes #159 --- lib/igniter.ex | 2 +- lib/igniter/project/module.ex | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/igniter.ex b/lib/igniter.ex index 6dcc5d5..c1985e1 100644 --- a/lib/igniter.ex +++ b/lib/igniter.ex @@ -1534,7 +1534,7 @@ defmodule Igniter do igniter.moves |> Enum.sort_by(&elem(&1, 0)) |> Enum.map(fn {from, to} -> - [:red, from, :reset, ": ", :green, to] + [:red, Path.relative_to_cwd(from), :reset, ": ", :green, to] end) |> display_list("These files will be moved:") end diff --git a/lib/igniter/project/module.ex b/lib/igniter/project/module.ex index 3c43d33..c9fef67 100644 --- a/lib/igniter/project/module.ex +++ b/lib/igniter/project/module.ex @@ -445,18 +445,15 @@ defmodule Igniter.Project.Module do List.starts_with?(Path.split(path), Path.split(inside_matching_folder_dirname)) end) - should_use_inside_matching_folder? = - if opts[:move_all?] do - dir?(igniter, inside_matching_folder_dirname) || just_created_folder? - else - source.path == proper_location(igniter, module, location_type) && - !dir?(igniter, inside_matching_folder_dirname) && just_created_folder? + if opts[:move_all?] || Rewrite.Source.from?(source, :string) do + if dir?(igniter, inside_matching_folder_dirname) || just_created_folder? do + inside_matching_folder end - - if should_use_inside_matching_folder? do - inside_matching_folder else - proper_location + if source.path == proper_location(igniter, module, location_type) && + !dir?(igniter, inside_matching_folder_dirname) && just_created_folder? do + inside_matching_folder + end end :outside_matching_folder ->