diff --git a/src/scalafix/scala/fix/MatchForMaterialToErrorForPerformance.scala b/src/scalafix/scala/fix/MatchForMaterialToErrorForPerformance.scala new file mode 100644 index 0000000000..a1d058274a --- /dev/null +++ b/src/scalafix/scala/fix/MatchForMaterialToErrorForPerformance.scala @@ -0,0 +1,31 @@ +package fix + +import scalafix.v1._ + +import scala.meta._ + +/** + * Lints on string interpolation where its variable part contains `case class` without `toString`. + */ +// noinspection ScalaUnusedSymbol; referred from scalafix implicitly +// NOTE: see AST on https://xuwei-k.github.io/scalameta-ast/ or https://astexplorer.net +class MatchForMaterialToErrorForPerformance extends SemanticRule("MatchForMaterialToErrorForPerformance") { + override def fix(implicit doc: SemanticDocument): Patch = { + doc.tree.collect { + case t @ Term.Match.After_4_4_5(term, _, _) => + term.symbol.info match { + case Some(info) if info.signature.toString == "Material" => + info.signature match { + case ValueSignature(TypeRef(_, symbol, _)) if SymbolMatcher.normalized("org/bukkit/Material").matches(symbol) => + val message = + s""" + |Don't use org.bukkit.Material in scrutinee of match expressions! + |See https://github.com/GiganticMinecraft/SeichiAssist/issues/2226 for more detail.""".stripMargin + Patch.lint(Diagnostic("error", message, t.pos)) + case _ => Patch.empty + } + case _ => Patch.empty + } + }.asPatch + } +}