scalafix icon indicating copy to clipboard operation
scalafix copied to clipboard

make undocumented replace rules safe to use

Open bjaglin opened this issue 5 years ago • 0 comments
trafficstars

https://github.com/scalacenter/scalafix/blob/d55b09bc18fe97686bd995fa44186e9ea18e9772/scalafix-tests/input/src/main/scala/test/ReplaceSymbol.scala#L1-L29 demonstrates usage of simple symbol replacements via --rules=replace:from/to and via the patches.replaceSymbols configuration key, backed by https://github.com/scalacenter/scalafix/blob/6811967f6e6059a59d8b04e7f2b76eb3c3ddcfbc/scalafix-core/src/main/scala/scalafix/patch/Patch.scala#L125-L143

As of 0.10.4, this is not documented publicly in tutorials (but does appear in the scaladoc) as it doesn’t handle some important cases leading to generating broken code.

From https://gitter.im/scalacenter/scalafix?at=5eeb039a405be935cda9fe27

At the top of my head, renaming a method won’t rename overrides/supermethods. The rename functionality in metals and IntelliJ are more reliable since they handle such cases. There are some cases the replace rule can do stuff I haven’t seen in IntelliJ or metals (for example replace usage of com.foo.Bar with org.foo.Bar, not definition site) but it’s not obvious for users to evaluate what cases will generate valid rewrites and what cases generate broken code.

bjaglin avatar Jun 18 '20 06:06 bjaglin