How can I prevent the usage of a specific implicit in my scala code?
For example, I was recently bit by the default Codec
provided by https://github.com/scala/scala/blob/68bad81726d15d03a843dc476d52cbbaf52fb168/src/library/scala/io/Codec.scala#L76.
Is there a way to ensure that any code that calls for an implicit codec: Codec
never uses the one provided by fallbackSystemCodec
?
Alternatively, is it possible to block all implicit Codecs?
Is this something that should be doable using scalafix?
Scalafix can inspect implicit arguments using
SemanticTree
. Here is an example solution by defining a custom scalafix rule.Given
we can define a custom rule
and corresponding
.scalafix.conf
should enable
sbt scalafix
to raise the diagnosticNote the output of
println(term.synthetic.structure)
Clearly the above solution is not efficient as it searches strings, however it should give some direction. Perhaps matching on
ApplyTree(func, args)
would be better.scalafix-exclude-implicits-example shows how to configure the project to use
ExcludedImplicitsRule
.