Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Material に対する match を error にする Scalafix rule を追加 #2227

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" =>
loliGothicK marked this conversation as resolved.
Show resolved Hide resolved
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
}
}