Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created August 8, 2022 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/35be6761709714852487df2a51d5b58b to your computer and use it in GitHub Desktop.
Save xuwei-k/35be6761709714852487df2a51d5b58b to your computer and use it in GitHub Desktop.
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