Created
August 8, 2022 10:28
-
-
Save xuwei-k/35be6761709714852487df2a51d5b58b to your computer and use it in GitHub Desktop.
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
package fix | |
import scalafix.Diagnostic | |
import scalafix.Patch | |
import scalafix.v1.SyntacticDocument | |
import scalafix.v1.SyntacticRule | |
import scala.meta.Term | |
import scalafix.lint.LintSeverity | |
class WrongStringInterpolation extends SyntacticRule("WrongStringInterpolation") { | |
private val upperCaseChars = 'A' to 'Z' | |
override def fix(implicit doc: SyntacticDocument): Patch = { | |
doc.tree.collect { | |
case t @ Term.Interpolate(Term.Name("s"), _, args) => | |
if ( | |
args.collectFirst { | |
case Term.Name(name) if upperCaseChars.contains(name.head) => true | |
}.nonEmpty | |
) { | |
Patch.lint( | |
new Diagnostic { | |
override def message = "string interpolationに渡す変数が間違ってませんか???" | |
override def severity = LintSeverity.Warning | |
override def position = t.pos | |
} | |
) | |
} else { | |
Patch.empty | |
} | |
}.asPatch | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment