Created
February 4, 2020 08:25
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
package example | |
import org.wartremover.{ WartTraverser, WartUniverse } | |
object ScalapbDefaultArgumentWarts extends WartTraverser { | |
def apply(u: WartUniverse): u.Traverser = { | |
import u.universe._ | |
val ApplyName = TermName("apply") | |
new Traverser { | |
override def traverse(tree: Tree): Unit = { | |
tree match { | |
case t if hasWartAnnotation(u)(t) => | |
case t if t.pos.source.path.contains("src_managed") => | |
// 自動生成コードは除くための設定。 | |
// TODO 除く方法が少し無理矢理感があるので、もっと適切な方法・・・ | |
case Apply(Select(a, ApplyName), _) | |
if a.tpe.baseClasses.exists(x => x.fullName.toString.startsWith("scalapb.GeneratedMessageCompanion")) && a.symbol.fullName != "com.google.protobuf.empty.Empty" => | |
warning(u)( | |
tree.pos, | |
"scalapbが生成したobjectのapplyはデフォルト引数を意図せず使ってしまうバグの原因になりやすいので使用禁止です。ofを使ってください" | |
) | |
case _ => | |
} | |
super.traverse(tree) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment