-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2227 from GiganticMinecraft/feature/scalafix-for-…
…match-for-material feat: Material に対する match を error にする Scalafix rule を追加
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/scalafix/scala/fix/MatchForMaterialToErrorForPerformance.scala
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
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 | ||
} | ||
} |