Last active
November 4, 2017 11:11
-
-
Save erikwj/fc54dcdc93e450ab3ce1d8670c5e3ef6 to your computer and use it in GitHub Desktop.
Changes a case class Foo(_type: String) into case class Foo(`type`: String)
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
/** | |
* Changes a case class Foo(_type: String) into case class Foo(`type`: String) | |
*/ | |
case class UseBackTicks(index: SemanticdbIndex) extends SemanticRule(index, "UseBackTicks") { | |
override def fix(ctx: RuleCtx): Patch = { | |
val reservedWords = Set( | |
// Scala | |
"abstract", "case", "catch", "class", "def", "do", "else", "extends", "false", "final", "finally", "for", "forSome", "if", "implicit", "import", "lazy", "match", "new", "null", "object", "override", "package", "private", "protected", "return", "sealed", "super", "this", "throw", "trait", "try", "true", "type", "val", "var", "while", "with", "yield", | |
// Scala-interop languages keywords | |
"abstract", "continue", "switch", "assert", "default", "synchronized", "goto", "break", "double", "implements", "byte", "public", "throws", "enum", "instanceof", "transient", "int", "short", "char", "interface", "static", "void", "finally", "long", "strictfp", "volatile", "const", "float", "native") | |
ctx.tree.collect { | |
case t @ Term.Name(value) if value.startsWith("_") && reservedWords.contains(value.replaceAll("_","")) => | |
ctx.replaceTree (t, s"`${value.replaceAll("_","")}`") | |
}.asPatch | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment