Created
June 14, 2020 07:33
-
-
Save xuwei-k/3fa03b1c9f1f55bbd830c35f04e5e19a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalafix.v1._ | |
import scala.meta._ | |
class ThrowableToNonFatal extends SemanticRule("ThrowableToNonFatal") { | |
override def fix(implicit doc: SemanticDocument): Patch = { | |
doc.tree.collect { | |
case c @ Case(Pat.Typed(v, Type.Name("Throwable")), _, _) => | |
List( | |
Patch.addGlobalImport(importer"scala.util.control.NonFatal"), | |
Patch.replaceTree( | |
c.pat, | |
s"NonFatal(${v.syntax})" | |
) | |
).asPatch | |
}.asPatch | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment