doorgan/sourceror

Error when formatting project

ivan-srsen opened this issue · 5 comments

I made my own formatter using sourceror and sometimes receive an error when trying to format the project.
It seems like it searches for a random dependency in deps folder every time I run it, and if that folder has .formatter.exs, it works, but otherwise not

mix format failed for file: lib/sf_sportradar_volleyball_parser/parsers/utility_parser.ex
** (Code.LoadError) could not load /Users/ivansrsen/projects/project/deps/idna/.formatter.exs
(elixir 1.13.4) lib/code.ex:1733: Code.find_file/2
(elixir 1.13.4) lib/code.ex:1122: Code.eval_file/2
(mix 1.13.4) lib/mix/tasks/format.ex:417: Mix.Tasks.Format.eval_file_with_keyword_list/1
(mix 1.13.4) lib/mix/tasks/format.ex:242: Mix.Tasks.Format.eval_dot_formatter/1
(mix 1.13.4) lib/mix/tasks/format.ex:218: Mix.Tasks.Format.formatter_for_file/2
lib/sourceror.ex:921: Sourceror.locals_without_parens/0
lib/sourceror.ex:211: Sourceror.to_string/2
lib/my_formatter.ex:46: MyFormatter.format/2

Hi @ivan-srsen

In your plugin you implement def format(contents, opts), do you give both arguments to Sourceror.to_string(contents, opts)? If this the case then you can try Sourceror.to_string(contents, Keyword.put_new(opts, :locals_without_parens, [])).

I think you can close the issue elixir-lang/elixir#12466 in the Elixir repo.

I was just using Sourceror.to_string(contents) but now I added your proposal and the error is still present. @NickNeck

@ivan-srsen sorry that was just the half truth. I have opened a PR to fix the other half. 🤞

The fix was merged, can you give it a shot with the main branch and see if the issue persists?

Seems like it's fixed, good job @NickNeck