hrzndhrn / recode

A linter with autocorrection and a refactoring tool.
MIT License
283 stars 15 forks source link

Feature Request: Respect formatter plugins #42

Closed axelson closed 1 year ago

axelson commented 1 year ago

Hi, thanks for Recode! It looks great!

I'm running into an issue when trying to use recode in a production application. When the elixir application depends on a formatter plugin (such as https://github.com/marcandre/freedom_formatter) then it appears that mix recode formats the code without using that formatter plugin.

I've created a minimal reproduction of this issue: https://github.com/axelson/recode_formatter_repro

NickNeck commented 1 year ago

Thanks for reporting this. I will take a look.

NickNeck commented 1 year ago

The problem is that Code.format_string!/2 ignores the option :plugins. To fix this for recode I will made PRs for recode, rewrite and sourceror, the next days. Maybe I will make also a PR in the Elixir repo.

NickNeck commented 1 year ago

I have made two PRs that should solve this issue. You can try it in your recode_formatter_repo with:

  defp deps do
    [
      {:freedom_formatter, ">= 2.0.0", only: :dev},
      {:recode, git: "https://github.com/hrzndhrn/recode", branch: "formatter"},
      {:rewrite, git: "https://github.com/hrzndhrn/rewrite", branch: "formatter", override: true}
    ]
  end

I will double check some things at the weekend and make the releases.

The solution is more a workaround. In rewrite not all plugins will be respected but the FreedomFormatter will be respected.

Thanks for the issue. I have learned some new things.

Have a nice weekend.

axelson commented 1 year ago

Thanks, I can confirm that my repro project works great after upgrading to recode 0.4.3 (and rewrite 0.4.2)! And it also work on a larger project as well, thank you! :+1: