Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created June 14, 2020 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/3fa03b1c9f1f55bbd830c35f04e5e19a to your computer and use it in GitHub Desktop.
Save xuwei-k/3fa03b1c9f1f55bbd830c35f04e5e19a to your computer and use it in GitHub Desktop.
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