doorgan / sourceror

Utilities to manipulate Elixir source code
Apache License 2.0
325 stars 22 forks source link

parse then to_string crashes #132

Closed bcardarella closed 5 months ago

bcardarella commented 5 months ago

I'm on v1.1 parsing a Phoenix app's config.exs and tried to put it back into a string:

File.read!("config/config.exs")
|> Sourceror.parse_string!()
|> Sourceror.to_string()

and I get this stacktrarce:

** (Mix.Error) Unknown dependency :ecto_sql given to :import_deps in the formatter configuration. Make sure the dependency is listed in your mix.exs for environment :dev and you have run "mix deps.get"
    (mix 1.16.2) lib/mix.ex:580: Mix.raise/2
    (mix 1.16.2) lib/mix/tasks/format.ex:415: anonymous fn/3 in Mix.Tasks.Format.eval_deps_opts/1
    (elixir 1.16.2) lib/enum.ex:2528: Enum."-reduce/3-lists^foldl/2-0-"/3
    (mix 1.16.2) lib/mix/tasks/format.ex:414: Mix.Tasks.Format.eval_deps_opts/1
    (mix 1.16.2) lib/mix/tasks/format.ex:361: anonymous fn/4 in Mix.Tasks.Format.eval_deps_and_subdirectories/4
    (mix 1.16.2) lib/mix/tasks/format.ex:359: Mix.Tasks.Format.eval_deps_and_subdirectories/4
    (mix 1.16.2) lib/mix/tasks/format.ex:438: anonymous fn/2 in Mix.Tasks.Format.eval_subs_opts/3
    (elixir 1.16.2) lib/enum.ex:1301: anonymous fn/3 in Enum.flat_map_reduce/3
    (elixir 1.16.2) lib/enum.ex:4839: Enumerable.List.reduce/3
    (elixir 1.16.2) lib/enum.ex:1300: Enum.flat_map_reduce/3
    (mix 1.16.2) lib/mix/tasks/format.ex:360: anonymous fn/4 in Mix.Tasks.Format.eval_deps_and_subdirectories/4
    (mix 1.16.2) lib/mix/tasks/format.ex:380: Mix.Tasks.Format.maybe_cache_in_manifest/3
    (mix 1.16.2) lib/mix/tasks/format.ex:359: Mix.Tasks.Format.eval_deps_and_subdirectories/4
    (mix 1.16.2) lib/mix/tasks/format.ex:307: Mix.Tasks.Format.formatter_for_file/2
    (sourceror 1.1.0) lib/sourceror.ex:946: Sourceror.locals_without_parens/0
    (elixir 1.16.2) lib/keyword.ex:806: Keyword.put_new_lazy/3
    (sourceror 1.1.0) lib/sourceror.ex:237: Sourceror.to_algebra/2
    (sourceror 1.1.0) lib/sourceror.ex:205: Sourceror.to_string/2

this is the exact file: https://gist.github.com/bcardarella/331c2a880ee38f72d6f70c1998382da6

bcardarella commented 5 months ago

Closing as this is not a bug with Sourceror.

Ona project that had removed ecto but didn't clean up everything. The .formatter files still had references to :ecto_sql