Skip to content

Commit

Permalink
fix: don't move modules back to their "proper" location
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zachdaniel committed Nov 25, 2024
1 parent 1045aec commit 9e638ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/igniter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions lib/igniter/project/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 9e638ea

Please sign in to comment.