Last active
November 14, 2018 16:58
-
-
Save erikwj/1c576d0f78a095dc7ff2e14ebb71c8a9 to your computer and use it in GitHub Desktop.
Converts Seq to List
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
import scalafix._ | |
import scalafix.Patch | |
import scalafix.SemanticdbIndex | |
import scalafix.rule.RuleCtx | |
import scalafix.rule.SemanticRule | |
import scala.meta._ | |
import contrib._ | |
import scalafix.lint.LintMessage | |
case class SeqToList(index: SemanticdbIndex) extends SemanticRule(index, "SeqToList") { | |
def isSeq = (n: Term.Name) => n.value == "Seq" | |
override def fix(ctx: RuleCtx): Patch = { | |
ctx.tree.collect { | |
case t @ Term.Name(_) if isSeq(t) => | |
ctx.replaceTree (t,"List") | |
case op @ Term.Name(value) if value == "+:" => | |
ctx.replaceTree (op,"::") | |
case tseq @ Term.Name(value) if value == "toSeq" => | |
ctx.replaceTree (tseq,"toList") | |
case typ @ Type.Name(value) if value == "Seq" => | |
ctx.replaceTree (typ,"List") | |
} | |
}.asPatch | |
//override def check(ctx: RuleCtx): Seq[LintMessage] = { | |
// ctx.tree.collect { | |
// case [email protected](_) if isSeq(t) => | |
// LintMessage(s"we only use List for collections", t.pos, LintCategory.error(s"Do not use Seq")) | |
// } | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment