uber-go / gopatch

Refactoring and code transformation tool for Go.
MIT License
917 stars 33 forks source link

Add an option to disable automatic code formatting #125

Open tchung1118 opened 1 year ago

tchung1118 commented 1 year ago

Currently when you use the following patch:

@@
var x expression
@@
-x.Enabled(true)
+x.Enabled()

This automatically reformats the expression matched to x, and that could make a lot of unwanted changes. For example, if the original code looks like this:

a.Foo().Bar(bar)
    .Baz(baz)
    .Enabled(true)

The resulting code after applying the patch becomes a one-liner:

a.Foo().Bar(bar).Baz(baz).Enabled()

Adding an option to disable the automatic formatting of code when applying patches could be nice for cases like this. For example, with that option, the resulting code would look like this:

a.Foo().Bar(bar)
    .Baz(baz)
    .Enabled()
lhanjian commented 7 months ago

It is necessary to reduce unnecessary diff generation ​