Skip to content

Commit

Permalink
Merge pull request #2227 from GiganticMinecraft/feature/scalafix-for-…
Browse files Browse the repository at this point in the history
…match-for-material

feat: Material に対する match を error にする Scalafix rule を追加
  • Loading branch information
kory33 authored Sep 18, 2023
2 parents 2d52d7f + 2e7ede1 commit 9684033
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/scalafix/scala/fix/MatchForMaterialToErrorForPerformance.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 9684033

Please sign in to comment.