erlfmt icon indicating copy to clipboard operation
erlfmt copied to clipboard

add library module for converting between erlfmt and syntax tools

Open richcarl opened this issue 3 years ago • 10 comments

Allows roundtrip conversion from erlfmt:read_nodes() to syntax tools (or erl_parse) and back to erlfmt:format_nodes().

richcarl avatar Jan 14 '21 12:01 richcarl

This certainly looks useful for writing refactoring tools in erlang itself.

We are having a hard time deciding if this belongs in erlfmt or a separate library: If we merge it in erlfmt, we would need to maintain it and if we don't merge it, then we would need to document our abstract_forms types better. To merge in erlfmt in would need a barrage of tests, that would make us confident that we can maintain it. Are you willing to do this work?

I only skimmed the code, but I saw a lot of TODOs are they intended to be fixed before merge or ...?

awalterschulze avatar Jan 18 '21 10:01 awalterschulze

No, the TODOs are meant for doing later, they're not blocking anything. But this code needs to find a home first, and I'm intending to do the work on it. Also hoping to work on reducing the internal differences between erlfmt and syntax tools so the conversion becomes less complicated in places.

richcarl avatar Jan 18 '21 11:01 richcarl

Do you also intend to add a barrage of tests, something in the order of https://github.com/WhatsApp/erlfmt/blob/master/test/erlfmt_format_SUITE.erl ?

Knowing this would help us to make a decision.

awalterschulze avatar Jan 18 '21 11:01 awalterschulze

That would probably be relatively easy to do, just adapting the existing tests and checking that the round-tripped code looks the same, so yes.

richcarl avatar Jan 18 '21 11:01 richcarl

That would be one way to get quite a large of coverage, but feel free to take some liberty on what you think is sensible.

Do you also maybe have thoughts on why you think this is the right home for this code?

awalterschulze avatar Jan 18 '21 14:01 awalterschulze

I think this is the right home, because the erlfmt format doesn't officially exist outside this app. By having the conversion functions here, nobody should need to know about it or depend on it. Also, it becomes easy to make synchronized changes in erlfmt internals and the conversion functions with a single commit.

richcarl avatar Jan 18 '21 14:01 richcarl

We have talked and you make a compelling argument :D Lets consider this the future home of this code, but lets also get some tests before merging.

awalterschulze avatar Jan 20 '21 15:01 awalterschulze

I think this is ready now.

richcarl avatar Jan 26 '21 13:01 richcarl

I'm currently pondering what changes I can make in syntax tools that will preserve compatibility with existing code that's using it, but being better at representing the same things under the hood that erlfmt does. Some of those TODOs require that sort of change first. Some other things may be possible to just change on the erlfmt side (after consulting you) and for those I could open tickets if you like.

richcarl avatar Jan 27 '21 12:01 richcarl

Is it possible to label the TODOs in the code as syntax_tools TODOs and actual TODOs for this code, to try and make it clear what is do-able by someone only looking at this code? It would at least help me to discern between them.

awalterschulze avatar Jan 27 '21 13:01 awalterschulze