Created
July 7, 2022 11:08
-
-
Save xuwei-k/d934912d072c3c4a1f861926e68419a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fix | |
import scalafix.Patch | |
import scalafix.v1.SyntacticDocument | |
import scalafix.v1.SyntacticRule | |
import scala.meta.Position | |
import scala.meta.Term | |
import scalafix.lint.Diagnostic | |
import scalafix.lint.LintSeverity | |
class SumFoldMap extends SyntacticRule("SumFoldMap") { | |
override def fix(implicit doc: SyntacticDocument): Patch = { | |
doc.tree.collect { | |
case t @ Term.Select( | |
Term.Apply( | |
Term.Select( | |
_, | |
Term.Name("map") | |
), | |
func :: Nil // TODO 色々なパターン正確に検知するのが面倒なので雑 | |
), | |
Term.Name("sum") | |
) => | |
Patch.lint(SumFoldMapWran(t.pos)) | |
}.asPatch | |
} | |
} | |
case class SumFoldMapWran(override val position: Position) extends Diagnostic { | |
override def message: String = "gakuzzzzさんに見つかる前に、mapしてsumはfoldMapに書き換えましょう" | |
override def severity = LintSeverity.Warning | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment